@@ -473,14 +473,14 @@ func listGoFiles(magePath, goCmd, tag string, envStr []string) ([]string, error)
473473 if ! filepath .IsAbs (magePath ) {
474474 cwd , err := os .Getwd ()
475475 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 ) )
477477 }
478478 magePath = filepath .Join (cwd , magePath )
479479 }
480480
481481 env , err := internal .SplitEnv (envStr )
482482 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 ) )
484484 }
485485
486486 bctx := build .Default
@@ -502,7 +502,7 @@ func listGoFiles(magePath, goCmd, tag string, envStr []string) ([]string, error)
502502
503503 // Allow multiple packages in the same directory
504504 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 ) )
506506 }
507507 }
508508
@@ -530,7 +530,7 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isMagefil
530530 debug .Println ("getting all files including those with mage tag in" , magePath )
531531 mageFiles , err := listGoFiles (magePath , goCmd , "mage" , env )
532532 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 ) )
534534 }
535535
536536 if isMagefilesDirectory {
@@ -546,7 +546,7 @@ func Magefiles(magePath, goos, goarch, goCmd string, stderr io.Writer, isMagefil
546546 debug .Println ("getting all files without mage tag in" , magePath )
547547 nonMageFiles , err := listGoFiles (magePath , goCmd , "" , env )
548548 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 ) )
550550 }
551551
552552 // convert non-Mage list to a map of files to exclude.
@@ -612,7 +612,7 @@ func GenerateMainfile(binaryName, path string, info *parse.PkgInfo) error {
612612
613613 f , err := os .Create (path )
614614 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 ) )
616616 }
617617 defer f .Close ()
618618 data := mainfileTemplateData {
@@ -629,16 +629,16 @@ func GenerateMainfile(binaryName, path string, info *parse.PkgInfo) error {
629629
630630 debug .Println ("writing new file at" , path )
631631 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 ) )
633633 }
634634 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 ) )
636636 }
637637 // we set an old modtime on the generated mainfile so that the go tool
638638 // won't think it has changed more recently than the compiled binary.
639639 longAgo := time .Now ().Add (- time .Hour * 24 * 365 * 10 )
640640 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 ) )
642642 }
643643 return nil
644644}
@@ -675,13 +675,13 @@ func ExeName(goCmd, cacheDir string, files []string) (string, error) {
675675func hashFile (fn string ) (string , error ) {
676676 f , err := os .Open (fn )
677677 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 ) )
679679 }
680680 defer f .Close ()
681681
682682 h := sha1 .New ()
683683 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 ) )
685685 }
686686 return fmt .Sprintf ("%x" , h .Sum (nil )), nil
687687}
@@ -690,12 +690,12 @@ func generateInit(dir string) error {
690690 debug .Println ("generating default magefile in" , dir )
691691 f , err := os .Create (filepath .Join (dir , initFile ))
692692 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 ) )
694694 }
695695 defer f .Close ()
696696
697697 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 ) )
699699 }
700700
701701 return nil
0 commit comments