@@ -473,14 +473,14 @@ func listGoFiles(magePath, goCmd, tag string, envStr []string) ([]string, error)
473
473
if ! filepath .IsAbs (magePath ) {
474
474
cwd , err := os .Getwd ()
475
475
if err != nil {
476
- return nil , fmt .Errorf ("can't get current working directory: %v" , err )
476
+ return nil , mg . WrapError ( err , fmt .Errorf ("can't get current working directory: %v" , err ) )
477
477
}
478
478
magePath = filepath .Join (cwd , magePath )
479
479
}
480
480
481
481
env , err := internal .SplitEnv (envStr )
482
482
if err != nil {
483
- return nil , fmt .Errorf ("error parsing environment variables: %v" , err )
483
+ return nil , mg . WrapError ( err , fmt .Errorf ("error parsing environment variables: %v" , err ) )
484
484
}
485
485
486
486
bctx := build .Default
@@ -502,7 +502,7 @@ func listGoFiles(magePath, goCmd, tag string, envStr []string) ([]string, error)
502
502
503
503
// Allow multiple packages in the same directory
504
504
if _ , ok := err .(* build.MultiplePackageError ); ! ok {
505
- return nil , fmt .Errorf ("failed to parse go source files: %v" , err )
505
+ return nil , mg . WrapError ( err , fmt .Errorf ("failed to parse go source files: %v" , err ) )
506
506
}
507
507
}
508
508
@@ -530,7 +530,7 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isMagefil
530
530
debug .Println ("getting all files including those with mage tag in" , magePath )
531
531
mageFiles , err := listGoFiles (magePath , goCmd , "mage" , env )
532
532
if err != nil {
533
- return nil , fmt .Errorf ("listing mage files: %v" , err )
533
+ return nil , mg . WrapError ( err , fmt .Errorf ("listing mage files: %v" , err ) )
534
534
}
535
535
536
536
if isMagefilesDirectory {
@@ -546,7 +546,7 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isMagefil
546
546
debug .Println ("getting all files without mage tag in" , magePath )
547
547
nonMageFiles , err := listGoFiles (magePath , goCmd , "" , env )
548
548
if err != nil {
549
- return nil , fmt .Errorf ("listing non-mage files: %v" , err )
549
+ return nil , mg . WrapError ( err , fmt .Errorf ("listing non-mage files: %v" , err ) )
550
550
}
551
551
552
552
// convert non-Mage list to a map of files to exclude.
@@ -612,7 +612,7 @@ func GenerateMainfile(binaryName, path string, info *parse.PkgInfo) error {
612
612
613
613
f , err := os .Create (path )
614
614
if err != nil {
615
- return fmt .Errorf ("error creating generated mainfile: %v" , err )
615
+ return mg . WrapError ( err , fmt .Errorf ("error creating generated mainfile: %v" , err ) )
616
616
}
617
617
defer f .Close ()
618
618
data := mainfileTemplateData {
@@ -629,16 +629,16 @@ func GenerateMainfile(binaryName, path string, info *parse.PkgInfo) error {
629
629
630
630
debug .Println ("writing new file at" , path )
631
631
if err := mainfileTemplate .Execute (f , data ); err != nil {
632
- return fmt .Errorf ("can't execute mainfile template: %v" , err )
632
+ return mg . WrapError ( err , fmt .Errorf ("can't execute mainfile template: %v" , err ) )
633
633
}
634
634
if err := f .Close (); err != nil {
635
- return fmt .Errorf ("error closing generated mainfile: %v" , err )
635
+ return mg . WrapError ( err , fmt .Errorf ("error closing generated mainfile: %v" , err ) )
636
636
}
637
637
// we set an old modtime on the generated mainfile so that the go tool
638
638
// won't think it has changed more recently than the compiled binary.
639
639
longAgo := time .Now ().Add (- time .Hour * 24 * 365 * 10 )
640
640
if err := os .Chtimes (path , longAgo , longAgo ); err != nil {
641
- return fmt .Errorf ("error setting old modtime on generated mainfile: %v" , err )
641
+ return mg . WrapError ( err , fmt .Errorf ("error setting old modtime on generated mainfile: %v" , err ) )
642
642
}
643
643
return nil
644
644
}
@@ -675,13 +675,13 @@ func ExeName(goCmd, cacheDir string, files []string) (string, error) {
675
675
func hashFile (fn string ) (string , error ) {
676
676
f , err := os .Open (fn )
677
677
if err != nil {
678
- return "" , fmt .Errorf ("can't open input file for hashing: %# v" , err )
678
+ return "" , mg . WrapError ( err , fmt .Errorf ("can't open input file for hashing: %v" , err ) )
679
679
}
680
680
defer f .Close ()
681
681
682
682
h := sha1 .New ()
683
683
if _ , err := io .Copy (h , f ); err != nil {
684
- return "" , fmt .Errorf ("can't write data to hash: %v" , err )
684
+ return "" , mg . WrapError ( err , fmt .Errorf ("can't write data to hash: %v" , err ) )
685
685
}
686
686
return fmt .Sprintf ("%x" , h .Sum (nil )), nil
687
687
}
@@ -690,12 +690,12 @@ func generateInit(dir string) error {
690
690
debug .Println ("generating default magefile in" , dir )
691
691
f , err := os .Create (filepath .Join (dir , initFile ))
692
692
if err != nil {
693
- return fmt .Errorf ("could not create mage template: %v" , err )
693
+ return mg . WrapError ( err , fmt .Errorf ("could not create mage template: %v" , err ) )
694
694
}
695
695
defer f .Close ()
696
696
697
697
if err := initOutput .Execute (f , nil ); err != nil {
698
- return fmt .Errorf ("can't execute magefile template: %v" , err )
698
+ return mg . WrapError ( err , fmt .Errorf ("can't execute magefile template: %v" , err ) )
699
699
}
700
700
701
701
return nil
0 commit comments