Target is launched which should not be launched
whiterm opened this issue · comments
Roman Belyy commented
To reproduce this bug, it was necessary to run go run mage.go test4
several times, because this error is floating
// +build mage
package main
import (
"fmt"
"github.com/magefile/mage/mg"
)
func Test1() error {
fmt.Println("execute test1")
return fmt.Errorf("error test1")
}
func Test2() error {
mg.Deps(Test1)
fmt.Println("execute test2")
return nil
}
func Test3() error {
mg.Deps(Test2)
fmt.Println("execute test3")
return nil
}
func Test4() error {
mg.Deps(Test1, Test2, Test3)
fmt.Println("execute test4")
return nil
}
Output:
execute test1
execute test3
Error: error test1
error test1
exit status 1
test3
target is not expected to run
Nate Finch commented
Ooh crap, I think I see the problem. If test1 runs and errors out, it's still marked as "run", so test3 sees that it doesn't need to run test1 and assumes it had succeeded. Instead we need to mark test1 as a failure so that if anyone else tries to run it, they fail out.
Roman Belyy commented
I think you are right. I just changed the test code a little bit. And now the bug can be reproduced at every run
// +build mage
package main
import (
"fmt"
"time"
"github.com/magefile/mage/mg"
)
func Test1() error {
fmt.Println("execute test1")
return fmt.Errorf("error test1")
}
func Test2() error {
mg.Deps(Test1)
fmt.Println("execute test2")
return nil
}
func Test3() error {
time.Sleep(time.Second)
mg.Deps(Test2)
fmt.Println("execute test3")
return nil
}
func Test4() error {
mg.Deps(Test1, Test2, Test3)
fmt.Println("execute test4")
return nil
}