diff --git a/go.mod b/go.mod index f8371f2b4b8..ecd9e81aefe 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 // indirect github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 // indirect github.com/fsnotify/fsnotify v1.4.7 - github.com/go-errors/errors v1.0.1 github.com/gofrs/uuid v3.2.0+incompatible github.com/golang/protobuf v1.3.3 github.com/h2non/filetype v1.0.8 // indirect @@ -27,7 +26,7 @@ require ( github.com/mattn/go-runewidth v0.0.2 // indirect github.com/miekg/dns v1.0.5 // indirect github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583 github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/schollz/closestmatch v2.1.0+incompatible diff --git a/go.sum b/go.sum index 9bd0b267f71..a4b55be2b0b 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5/go.mod h1:BEUDl7 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= -github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= @@ -136,8 +134,8 @@ github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228/go.mod h1:MGuVJ1 github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583 h1:ogHi8YLNeIxABOaH6UgtbwkODheuAK+ErP8gWXYQVj0= diff --git a/legacy/builder/add_additional_entries_to_context.go b/legacy/builder/add_additional_entries_to_context.go index b87e1733166..775b6cdc63e 100644 --- a/legacy/builder/add_additional_entries_to_context.go +++ b/legacy/builder/add_additional_entries_to_context.go @@ -18,8 +18,8 @@ package builder import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type AddAdditionalEntriesToContext struct{} @@ -29,19 +29,19 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error { buildPath := ctx.BuildPath preprocPath, err := buildPath.Join(constants.FOLDER_PREPROC).Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } sketchBuildPath, err := buildPath.Join(constants.FOLDER_SKETCH).Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } librariesBuildPath, err := buildPath.Join("libraries").Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } coreBuildPath, err := buildPath.Join(constants.FOLDER_CORE).Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.PreprocPath = preprocPath @@ -53,7 +53,7 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error { if ctx.BuildCachePath != nil { coreBuildCachePath, err := ctx.BuildCachePath.Join(constants.FOLDER_CORE).Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.CoreBuildCachePath = coreBuildCachePath diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 107bcc3ed1e..195338d641c 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -25,10 +25,10 @@ import ( bldr "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/phases" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" + "github.com/pkg/errors" ) var MAIN_FILE_VALID_EXTENSIONS = map[string]bool{".ino": true, ".pde": true} @@ -194,7 +194,7 @@ func runCommands(ctx *types.Context, commands []types.Command, progressEnabled b builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } return nil diff --git a/legacy/builder/builder_utils/utils.go b/legacy/builder/builder_utils/utils.go index c8f0ffefd89..5e96c815541 100644 --- a/legacy/builder/builder_utils/utils.go +++ b/legacy/builder/builder_utils/utils.go @@ -30,6 +30,7 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) { @@ -48,18 +49,18 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) { func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } folders, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterDirs) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } for _, folder := range folders { subFolderObjectFiles, err := CompileFilesRecursive(ctx, sourcePath.Join(folder.Name()), buildPath.Join(folder.Name()), buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles.AddAll(subFolderObjectFiles) } @@ -70,15 +71,15 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { sObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } cObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".c", constants.RECIPE_C_PATTERN) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } cppObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".cpp", constants.RECIPE_CPP_PATTERN) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles := paths.NewPathList() objectFiles.AddAll(sObjectFiles) @@ -90,7 +91,7 @@ func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buil func compileFilesWithExtensionWithRecipe(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string, extension string, recipe string) (paths.PathList, error) { sources, err := findFilesInFolder(sourcePath, extension, recurse) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } return compileFilesWithRecipe(ctx, sourcePath, sources, buildPath, buildProperties, includes, recipe) } @@ -98,7 +99,7 @@ func compileFilesWithExtensionWithRecipe(ctx *types.Context, sourcePath *paths.P func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (paths.PathList, error) { files, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterFilesWithExtensions(extension)) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } var sources paths.PathList for _, file := range files { @@ -108,13 +109,13 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) ( if recurse { folders, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterDirs) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } for _, folder := range folders { otherSources, err := findFilesInFolder(sourcePath.Join(folder.Name()), extension, recurse) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } sources = append(sources, otherSources...) } @@ -126,7 +127,7 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) ( func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) { files, err := utils.ReadDirFiltered(sourcePath, utils.FilterFiles()) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } var sources []string for _, file := range files { @@ -136,7 +137,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) { if recurse { folders, err := utils.ReadDirFiltered(sourcePath, utils.FilterDirs) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } for _, folder := range folders { @@ -144,7 +145,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) { // Skip SCCS directories as they do not influence the build and can be very large otherSources, err := findAllFilesInFolder(filepath.Join(sourcePath, folder.Name()), recurse) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } sources = append(sources, otherSources...) } @@ -160,7 +161,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources return objectFiles, nil } var objectFilesMux sync.Mutex - var errors []error + var errorsList []error var errorsMux sync.Mutex ctx.Progress.Steps = ctx.Progress.Steps / float64(len(sources)) @@ -171,7 +172,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe) if err != nil { errorsMux.Lock() - errors = append(errors, err) + errorsList = append(errorsList, err) errorsMux.Unlock() } else { objectFilesMux.Lock() @@ -199,7 +200,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources // Feed jobs until error or done for _, source := range sources { errorsMux.Lock() - gotError := len(errors) > 0 + gotError := len(errorsList) > 0 errorsMux.Unlock() if gotError { break @@ -208,9 +209,9 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources } close(queue) wg.Wait() - if len(errors) > 0 { + if len(errorsList) > 0 { // output the first error - return nil, i18n.WrapError(errors[0]) + return nil, errors.WithStack(errorsList[0]) } objectFiles.Sort() return objectFiles, nil @@ -224,7 +225,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source) relativeSource, err := sourcePath.RelTo(source) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } depsFile := buildPath.Join(relativeSource.String() + ".d") objectFile := buildPath.Join(relativeSource.String() + ".o") @@ -232,17 +233,17 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile) err = objectFile.Parent().MkdirAll() if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objIsUpToDate, err := ObjFileIsUpToDate(ctx, source, objectFile, depsFile) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } if !objIsUpToDate { _, _, err = ExecRecipe(ctx, properties, recipe, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } } else if ctx.Verbose { logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, objectFile) @@ -267,7 +268,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil sourceFile = sourceFile.Clean() sourceFileStat, err := sourceFile.Stat() if err != nil { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } objectFile = objectFile.Clean() @@ -279,7 +280,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil } return false, nil } else { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } } @@ -292,7 +293,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil } return false, nil } else { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } } @@ -311,7 +312,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil rows, err := dependencyFile.ReadFileAsLines() if err != nil { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } rows = utils.Map(rows, removeEndingBackSlash) @@ -346,7 +347,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil // Ignore the error and trigger a full rebuild anyway if debugLevel >= 20 { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Failed to read: {0}", row) - logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, i18n.WrapError(err).Error()) + logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, err.Error()) } return false, nil } @@ -454,9 +455,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile // something changed, rebuild the core archive if rebuildArchive { - err = archiveFilePath.Remove() - if err != nil { - return nil, i18n.WrapError(err) + if err := archiveFilePath.Remove(); err != nil { + return nil, errors.WithStack(err) } } else { if ctx.Verbose { @@ -472,9 +472,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath) properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile) - _, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) - if err != nil { - return nil, i18n.WrapError(err) + if _, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show); err != nil { + return nil, errors.WithStack(err) } } @@ -485,7 +484,7 @@ func ExecRecipe(ctx *types.Context, buildProperties *properties.Map, recipe stri // See util.ExecCommand for stdout/stderr arguments command, err := PrepareCommandForRecipe(ctx, buildProperties, recipe, removeUnsetProperties) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } return utils.ExecCommand(ctx, command, stdout, stderr) @@ -514,7 +513,7 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map command, err := utils.PrepareCommand(commandLine, logger, relativePath) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } return command, nil diff --git a/legacy/builder/container_add_prototypes.go b/legacy/builder/container_add_prototypes.go index ddb1889367f..1a8c093b351 100644 --- a/legacy/builder/container_add_prototypes.go +++ b/legacy/builder/container_add_prototypes.go @@ -18,8 +18,8 @@ package builder import ( bldr "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type ContainerAddPrototypes struct{} @@ -27,14 +27,14 @@ type ContainerAddPrototypes struct{} func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { // Generate the full pathname for the preproc output file if err := ctx.PreprocPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } targetFilePath := ctx.PreprocPath.Join(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E) // Run preprocessor sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Name.Base() + ".cpp") if err := GCCPreprocRunner(ctx, sourceFile, targetFilePath, ctx.IncludeFolders); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } commands := []types.Command{ @@ -49,12 +49,12 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } if err := bldr.SketchSaveItemCpp(ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source), ctx.SketchBuildPath.String()); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil diff --git a/legacy/builder/container_build_options.go b/legacy/builder/container_build_options.go index bc8a5e45401..b06b9e9c763 100644 --- a/legacy/builder/container_build_options.go +++ b/legacy/builder/container_build_options.go @@ -16,8 +16,8 @@ package builder import ( - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type ContainerBuildOptions struct{} @@ -34,7 +34,7 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error { PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 2221c8cfde4..08b6796e6cc 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -102,12 +102,10 @@ import ( "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" - - "github.com/go-errors/errors" + "github.com/pkg/errors" ) type ContainerFindIncludes struct{} @@ -124,7 +122,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { sketch := ctx.Sketch mergedfile, err := types.MakeSourceFile(ctx, sketch, paths.New(sketch.MainFile.Name.Base()+".cpp")) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.CollectedSourceFiles.Push(mergedfile) @@ -139,7 +137,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { err := findIncludesUntilDone(ctx, cache, sourceFilePaths.Pop()) if err != nil { cachePath.Remove() - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -147,12 +145,12 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error { cache.ExpectEnd() err = writeCache(cache, cachePath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = runCommand(ctx, &FailIfImportedLibraryIsWrong{}) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil @@ -172,7 +170,7 @@ func runCommand(ctx *types.Context, command types.Command) error { PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil } @@ -276,11 +274,11 @@ func writeCache(cache *includeCache, path *paths.Path) error { } else { bytes, err := json.MarshalIndent(cache.entries, "", " ") if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = path.WriteFile(bytes) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } return nil @@ -306,7 +304,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t // remove the object file if it is found to be stale? unchanged, err := builder_utils.ObjFileIsUpToDate(ctx, sourcePath, objPath, depPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } first := true @@ -328,7 +326,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t } else { preproc_stderr, preproc_err = GCCPreprocRunnerForDiscoveringIncludes(ctx, sourcePath, targetFilePath, includes) // Unwrap error and see if it is an ExitError. - _, is_exit_error := i18n.UnwrapError(preproc_err).(*exec.ExitError) + _, is_exit_error := errors.Cause(preproc_err).(*exec.ExitError) if preproc_err == nil { // Preprocessor successful, done include = "" @@ -336,7 +334,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t // Ignore ExitErrors (e.g. gcc returning // non-zero status), but bail out on // other errors - return i18n.WrapError(preproc_err) + return errors.WithStack(preproc_err) } else { include = IncludesFinderWithRegExp(ctx, string(preproc_stderr)) if include == "" && ctx.Verbose { @@ -355,7 +353,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t if library == nil { // Library could not be resolved, show error // err := runCommand(ctx, &GCCPreprocRunner{SourceFilePath: sourcePath, TargetFileName: paths.New(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E), Includes: includes}) - // return i18n.WrapError(err) + // return errors.WithStack(err) if preproc_err == nil || preproc_stderr == nil { // Filename came from cache, so run preprocessor to obtain error to show preproc_stderr, preproc_err = GCCPreprocRunnerForDiscoveringIncludes(ctx, sourcePath, targetFilePath, includes) @@ -368,7 +366,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t } } os.Stderr.Write(preproc_stderr) - return i18n.WrapError(preproc_err) + return errors.WithStack(preproc_err) } // Add this library to the list of libraries, the @@ -390,13 +388,13 @@ func queueSourceFilesFromFolder(ctx *types.Context, queue *types.UniqueSourceFil filePaths := []string{} err := utils.FindFilesInFolder(&filePaths, folder.String(), extensions, recurse) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, filePath := range filePaths { sourceFile, err := types.MakeSourceFile(ctx, origin, paths.New(filePath)) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } queue.Push(sourceFile) } diff --git a/legacy/builder/container_merge_copy_sketch_files.go b/legacy/builder/container_merge_copy_sketch_files.go index 3f88c215434..bd7302e70a7 100644 --- a/legacy/builder/container_merge_copy_sketch_files.go +++ b/legacy/builder/container_merge_copy_sketch_files.go @@ -17,9 +17,8 @@ package builder import ( bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" - "github.com/go-errors/errors" + "github.com/pkg/errors" ) type ContainerMergeCopySketchFiles struct{} @@ -27,7 +26,7 @@ type ContainerMergeCopySketchFiles struct{} func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error { sk := types.SketchFromLegacy(ctx.Sketch) if sk == nil { - return i18n.WrapError(errors.New("unable to convert legacy sketch to the new type")) + return errors.New("unable to convert legacy sketch to the new type") } offset, source, err := bldr.SketchMergeSources(sk) if err != nil { @@ -37,11 +36,11 @@ func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error { ctx.Source = source if err := bldr.SketchSaveItemCpp(ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source), ctx.SketchBuildPath.String()); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if err := bldr.SketchCopyAdditionalFiles(sk, ctx.SketchBuildPath.String()); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil diff --git a/legacy/builder/container_setup.go b/legacy/builder/container_setup.go index 99e3e1e7e96..2561b60c732 100644 --- a/legacy/builder/container_setup.go +++ b/legacy/builder/container_setup.go @@ -20,9 +20,9 @@ import ( bldr "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) type ContainerSetupHardwareToolsLibsSketchAndProps struct{} @@ -47,7 +47,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -55,13 +55,13 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) // get abs path to sketch sketchLocation, err := ctx.SketchLocation.Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } // load sketch sketch, err := bldr.SketchLoad(sketchLocation.String(), ctx.BuildPath.String()) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if sketch.MainFile == nil { return fmt.Errorf("main file missing from sketch") @@ -84,7 +84,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } diff --git a/legacy/builder/create_build_options_map.go b/legacy/builder/create_build_options_map.go index b9de9b0cc45..8c667f592da 100644 --- a/legacy/builder/create_build_options_map.go +++ b/legacy/builder/create_build_options_map.go @@ -17,8 +17,9 @@ package builder import ( "encoding/json" - "github.com/arduino/arduino-cli/legacy/builder/i18n" + "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type CreateBuildOptionsMap struct{} @@ -27,7 +28,7 @@ func (s *CreateBuildOptionsMap) Run(ctx *types.Context) error { buildOptions := ctx.ExtractBuildOptions() bytes, err := json.MarshalIndent(buildOptions, "", " ") if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.BuildOptionsJson = string(bytes) diff --git a/legacy/builder/ctags_runner.go b/legacy/builder/ctags_runner.go index 240911bc840..72f1bd04a6b 100644 --- a/legacy/builder/ctags_runner.go +++ b/legacy/builder/ctags_runner.go @@ -21,6 +21,7 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" + "github.com/pkg/errors" ) type CTagsRunner struct{} @@ -42,12 +43,12 @@ func (s *CTagsRunner) Run(ctx *types.Context) error { commandLine := properties.ExpandPropsInString(pattern) command, err := utils.PrepareCommand(commandLine, logger, "") if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } sourceBytes, _, err := utils.ExecCommand(ctx, command, utils.Capture /* stdout */, utils.Ignore /* stderr */) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.CTagsOutput = string(sourceBytes) diff --git a/legacy/builder/ctags_target_file_saver.go b/legacy/builder/ctags_target_file_saver.go index f220e5b89e6..a4014662c41 100644 --- a/legacy/builder/ctags_target_file_saver.go +++ b/legacy/builder/ctags_target_file_saver.go @@ -16,8 +16,8 @@ package builder import ( - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type CTagsTargetFileSaver struct { @@ -30,12 +30,12 @@ func (s *CTagsTargetFileSaver) Run(ctx *types.Context) error { preprocPath := ctx.PreprocPath if err := preprocPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctagsTargetFilePath := preprocPath.Join(s.TargetFileName) if err := ctagsTargetFilePath.WriteFile([]byte(source)); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.CTagsTargetFile = ctagsTargetFilePath diff --git a/legacy/builder/fail_if_buildpath_equals_sketchpath.go b/legacy/builder/fail_if_buildpath_equals_sketchpath.go index 43ca72d1a16..7cd26b22680 100644 --- a/legacy/builder/fail_if_buildpath_equals_sketchpath.go +++ b/legacy/builder/fail_if_buildpath_equals_sketchpath.go @@ -19,6 +19,7 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type FailIfBuildPathEqualsSketchPath struct{} @@ -30,12 +31,12 @@ func (s *FailIfBuildPathEqualsSketchPath) Run(ctx *types.Context) error { buildPath, err := ctx.BuildPath.Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } sketchPath, err := ctx.SketchLocation.Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } sketchPath = sketchPath.Parent() diff --git a/legacy/builder/gcc_preproc_runner.go b/legacy/builder/gcc_preproc_runner.go index 8e62a59e089..fa33bd909fe 100644 --- a/legacy/builder/gcc_preproc_runner.go +++ b/legacy/builder/gcc_preproc_runner.go @@ -21,21 +21,21 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) func GCCPreprocRunner(ctx *types.Context, sourceFilePath *paths.Path, targetFilePath *paths.Path, includes paths.PathList) error { cmd, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } _, _, err = utils.ExecCommand(ctx, cmd /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil @@ -44,12 +44,12 @@ func GCCPreprocRunner(ctx *types.Context, sourceFilePath *paths.Path, targetFile func GCCPreprocRunnerForDiscoveringIncludes(ctx *types.Context, sourceFilePath *paths.Path, targetFilePath *paths.Path, includes paths.PathList) ([]byte, error) { cmd, err := prepareGCCPreprocRecipeProperties(ctx, sourceFilePath, targetFilePath, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } _, stderr, err := utils.ExecCommand(ctx, cmd /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Capture) if err != nil { - return stderr, i18n.WrapError(err) + return stderr, errors.WithStack(err) } return stderr, nil @@ -70,7 +70,7 @@ func prepareGCCPreprocRecipeProperties(ctx *types.Context, sourceFilePath *paths cmd, err := builder_utils.PrepareCommandForRecipe(ctx, properties, constants.RECIPE_PREPROC_MACROS, true) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } // Remove -MMD argument if present. Leaving it will make gcc try diff --git a/legacy/builder/hardware_loader.go b/legacy/builder/hardware_loader.go index b8eea9cd498..7d4c8a94627 100644 --- a/legacy/builder/hardware_loader.go +++ b/legacy/builder/hardware_loader.go @@ -17,8 +17,8 @@ package builder import ( "github.com/arduino/arduino-cli/arduino/cores/packagemanager" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type HardwareLoader struct{} @@ -27,7 +27,7 @@ func (s *HardwareLoader) Run(ctx *types.Context) error { if ctx.PackageManager == nil { pm := packagemanager.NewPackageManager(nil, nil, nil, nil) if err := pm.LoadHardwareFromDirectories(ctx.HardwareDirs); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.PackageManager = pm } diff --git a/legacy/builder/i18n/errors.go b/legacy/builder/i18n/errors.go index 97ac141c4f4..f21bde19fbc 100644 --- a/legacy/builder/i18n/errors.go +++ b/legacy/builder/i18n/errors.go @@ -1,31 +1,16 @@ package i18n -import "github.com/arduino/arduino-cli/legacy/builder/constants" -import "github.com/go-errors/errors" -import "os" +import ( + "os" -func ErrorfWithLogger(logger Logger, format string, a ...interface{}) *errors.Error { + "github.com/arduino/arduino-cli/legacy/builder/constants" + "github.com/pkg/errors" +) + +func ErrorfWithLogger(logger Logger, format string, a ...interface{}) error { if logger.Name() == "machine" { logger.Fprintln(os.Stderr, constants.LOG_LEVEL_ERROR, format, a...) - return errors.Errorf("") - } - return errors.Errorf(Format(format, a...)) -} - -func WrapError(err error) error { - if err == nil { - return nil - } - return errors.Wrap(err, 0) -} - -func UnwrapError(err error) error { - // Perhaps go-errors can do this already in later versions? - // See https://github.com/go-errors/errors/issues/14 - switch e := err.(type) { - case *errors.Error: - return e.Err - default: - return err + return errors.New("") } + return errors.New(Format(format, a...)) } diff --git a/legacy/builder/libraries_loader.go b/legacy/builder/libraries_loader.go index 6af87b5c57d..5abcdec5451 100644 --- a/legacy/builder/libraries_loader.go +++ b/legacy/builder/libraries_loader.go @@ -21,8 +21,8 @@ import ( "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/arduino/libraries/librariesresolver" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type LibrariesLoader struct{} @@ -33,7 +33,7 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { builtInLibrariesFolders := ctx.BuiltInLibrariesDirs if err := builtInLibrariesFolders.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, folder := range builtInLibrariesFolders { lm.AddLibrariesDir(folder, libraries.IDEBuiltIn) @@ -51,14 +51,14 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { librariesFolders := ctx.OtherLibrariesDirs if err := librariesFolders.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, folder := range librariesFolders { lm.AddLibrariesDir(folder, libraries.User) } if err := lm.RescanLibraries(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if debugLevel > 0 { @@ -66,7 +66,7 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { for _, libAlt := range lib.Alternatives { warnings, err := libAlt.Lint() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, warning := range warnings { logger.Fprintln(os.Stdout, "warn", warning) @@ -77,7 +77,7 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { resolver := librariesresolver.NewCppResolver() if err := resolver.ScanFromLibrariesManager(lm); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.LibrariesResolver = resolver diff --git a/legacy/builder/load_previous_build_options.go b/legacy/builder/load_previous_build_options.go index bf817278f51..b7b03e9c84d 100644 --- a/legacy/builder/load_previous_build_options.go +++ b/legacy/builder/load_previous_build_options.go @@ -17,8 +17,8 @@ package builder import ( "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/pkg/errors" ) type LoadPreviousBuildOptionsMap struct{} @@ -32,7 +32,7 @@ func (s *LoadPreviousBuildOptionsMap) Run(ctx *types.Context) error { bytes, err := buildOptionsFile.ReadFile() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.BuildOptionsJsonPrevious = string(bytes) diff --git a/legacy/builder/load_vid_pid_specific_properties.go b/legacy/builder/load_vid_pid_specific_properties.go index 0c51b9b706c..7cf0f5c517b 100644 --- a/legacy/builder/load_vid_pid_specific_properties.go +++ b/legacy/builder/load_vid_pid_specific_properties.go @@ -20,9 +20,9 @@ import ( "strings" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type LoadVIDPIDSpecificProperties struct{} @@ -41,7 +41,7 @@ func (s *LoadVIDPIDSpecificProperties) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties VIDPIDIndex, err := findVIDPIDIndex(buildProperties, vid, pid) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if VIDPIDIndex < 0 { return nil diff --git a/legacy/builder/merge_sketch_with_bootloader.go b/legacy/builder/merge_sketch_with_bootloader.go index 34fd33ee8f7..742d8f57db6 100644 --- a/legacy/builder/merge_sketch_with_bootloader.go +++ b/legacy/builder/merge_sketch_with_bootloader.go @@ -19,11 +19,10 @@ import ( "os" "strings" - "github.com/arduino/go-paths-helper" - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) type MergeSketchWithBootloader struct{} @@ -115,13 +114,13 @@ func extractActualBootloader(bootloader []string) []string { func merge(builtSketchPath, bootloaderPath, mergedSketchPath *paths.Path) error { sketch, err := builtSketchPath.ReadFileAsLines() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } sketch = sketch[:len(sketch)-2] bootloader, err := bootloaderPath.ReadFileAsLines() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } realBootloader := extractActualBootloader(bootloader) diff --git a/legacy/builder/phases/core_builder.go b/legacy/builder/phases/core_builder.go index 846fd30dbb6..52ecfcb1ae1 100644 --- a/legacy/builder/phases/core_builder.go +++ b/legacy/builder/phases/core_builder.go @@ -21,11 +21,11 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type CoreBuilder struct{} @@ -36,7 +36,7 @@ func (s *CoreBuilder) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties if err := coreBuildPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if coreBuildCachePath != nil { @@ -47,13 +47,13 @@ func (s *CoreBuilder) Run(ctx *types.Context) error { coreBuildCachePath = nil ctx.CoreBuildCachePath = nil } else if err := coreBuildCachePath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } archiveFile, objectFiles, err := compileCore(ctx, coreBuildPath, coreBuildCachePath, buildProperties) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.CoreArchiveFilePath = archiveFile @@ -82,7 +82,7 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path if variantFolder != nil && variantFolder.IsDir() { variantObjectFiles, err = builder_utils.CompileFiles(ctx, variantFolder, true, buildPath, buildProperties, includes) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } } @@ -107,12 +107,12 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path coreObjectFiles, err := builder_utils.CompileFiles(ctx, coreFolder, true, buildPath, buildProperties, includes) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, buildPath, paths.New("core.a"), coreObjectFiles, buildProperties) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } // archive core.a diff --git a/legacy/builder/phases/libraries_builder.go b/legacy/builder/phases/libraries_builder.go index b01ffe70dc2..28f39ca429b 100644 --- a/legacy/builder/phases/libraries_builder.go +++ b/legacy/builder/phases/libraries_builder.go @@ -23,11 +23,11 @@ import ( "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map[string]bool{".a": true} @@ -44,12 +44,12 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error { libs := ctx.ImportedLibraries if err := librariesBuildPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } objectFiles, err := compileLibraries(ctx, libs, librariesBuildPath, buildProperties, includes) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.LibrariesObjectFiles = objectFiles @@ -147,7 +147,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p for _, library := range libraries { libraryObjectFiles, err := compileLibrary(ctx, library, buildPath, buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles = append(objectFiles, libraryObjectFiles...) } @@ -163,7 +163,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p libraryBuildPath := buildPath.Join(library.Name) if err := libraryBuildPath.MkdirAll(); err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles := paths.NewPathList() @@ -180,7 +180,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p // Should we force precompiled libraries to start with "lib" ? err := utils.FindFilesInFolder(&filePaths, precompiledPath.String(), extensions, false) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } for _, path := range filePaths { if !strings.HasPrefix(filepath.Base(path), "lib") { @@ -194,12 +194,12 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p if library.Layout == libraries.RecursiveLayout { libObjectFiles, err := builder_utils.CompileFilesRecursive(ctx, library.SourceDir, libraryBuildPath, buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } if library.DotALinkage { archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, libraryBuildPath, paths.New(library.Name+".a"), libObjectFiles, buildProperties) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles.Add(archiveFile) } else { @@ -211,7 +211,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p } libObjectFiles, err := builder_utils.CompileFiles(ctx, library.SourceDir, false, libraryBuildPath, buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles.AddAll(libObjectFiles) @@ -219,7 +219,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p utilityBuildPath := libraryBuildPath.Join("utility") utilityObjectFiles, err := builder_utils.CompileFiles(ctx, library.UtilityDir, false, utilityBuildPath, buildProperties, includes) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } objectFiles.AddAll(utilityObjectFiles) } diff --git a/legacy/builder/phases/linker.go b/legacy/builder/phases/linker.go index e3dce2129e5..76884bf4602 100644 --- a/legacy/builder/phases/linker.go +++ b/legacy/builder/phases/linker.go @@ -20,11 +20,11 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type Linker struct{} @@ -43,14 +43,14 @@ func (s *Linker) Run(ctx *types.Context) error { buildPath := ctx.BuildPath coreDotARelPath, err := buildPath.RelTo(coreArchiveFilePath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } buildProperties := ctx.BuildProperties err = link(ctx, objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil diff --git a/legacy/builder/phases/sizer.go b/legacy/builder/phases/sizer.go index b572ada9e79..2d5b055c5bb 100644 --- a/legacy/builder/phases/sizer.go +++ b/legacy/builder/phases/sizer.go @@ -16,16 +16,15 @@ package phases import ( - "errors" "regexp" "strconv" "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type Sizer struct { @@ -42,7 +41,7 @@ func (s *Sizer) Run(ctx *types.Context) error { err := checkSize(ctx, buildProperties) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil diff --git a/legacy/builder/phases/sketch_builder.go b/legacy/builder/phases/sketch_builder.go index 83431bfb7b0..59055375fb5 100644 --- a/legacy/builder/phases/sketch_builder.go +++ b/legacy/builder/phases/sketch_builder.go @@ -18,9 +18,9 @@ package phases import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" + "github.com/pkg/errors" ) type SketchBuilder struct{} @@ -31,12 +31,12 @@ func (s *SketchBuilder) Run(ctx *types.Context) error { includes := utils.Map(ctx.IncludeFolders.AsStrings(), utils.WrapWithHyphenI) if err := sketchBuildPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } objectFiles, err := builder_utils.CompileFiles(ctx, sketchBuildPath, false, sketchBuildPath, buildProperties, includes) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } // The "src/" subdirectory of a sketch is compiled recursively @@ -44,7 +44,7 @@ func (s *SketchBuilder) Run(ctx *types.Context) error { if sketchSrcPath.IsDir() { srcObjectFiles, err := builder_utils.CompileFiles(ctx, sketchSrcPath, true, sketchSrcPath, buildProperties, includes) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } objectFiles.AddAll(srcObjectFiles) } diff --git a/legacy/builder/platform_keys_rewrite_loader.go b/legacy/builder/platform_keys_rewrite_loader.go index a4db9c21f7c..31709971c29 100644 --- a/legacy/builder/platform_keys_rewrite_loader.go +++ b/legacy/builder/platform_keys_rewrite_loader.go @@ -20,12 +20,11 @@ import ( "strconv" "strings" - "github.com/arduino/go-paths-helper" - "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" + "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type PlatformKeysRewriteLoader struct{} @@ -35,7 +34,7 @@ func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { platformKeysRewriteTxtPath, err := findPlatformKeysRewriteTxt(folders) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if platformKeysRewriteTxtPath == nil { return nil @@ -46,7 +45,7 @@ func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { txt, err := properties.LoadFromPath(platformKeysRewriteTxtPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } keys := txt.Keys() sort.Strings(keys) @@ -56,7 +55,7 @@ func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error { if keyParts[0] == constants.PLATFORM_REWRITE_OLD { index, err := strconv.Atoi(keyParts[1]) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } rewriteKey := strings.Join(keyParts[2:], ".") oldValue := txt.Get(key) @@ -78,7 +77,7 @@ func findPlatformKeysRewriteTxt(folders paths.PathList) (*paths.Path, error) { if exist, err := txtPath.ExistCheck(); exist { return txtPath, nil } else if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } } diff --git a/legacy/builder/preprocess_sketch.go b/legacy/builder/preprocess_sketch.go index 93e4fb97f70..9e87cae0906 100644 --- a/legacy/builder/preprocess_sketch.go +++ b/legacy/builder/preprocess_sketch.go @@ -16,7 +16,6 @@ package builder import ( - "errors" "fmt" "os/exec" "path/filepath" @@ -29,6 +28,7 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" properties "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) // ArduinoPreprocessorProperties are the platform properties needed to run arduino-preprocessor @@ -50,7 +50,7 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error { } if err := ctx.PreprocPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } GCCPreprocRunner(ctx, sourceFile, ctx.PreprocPath.Join(constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E), ctx.IncludeFolders) @@ -59,7 +59,7 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error { PrintRingNameIfDebug(ctx, command) err := command.Run(ctx) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -108,7 +108,7 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error { commandLine := properties.ExpandPropsInString(pattern) command, err := utils.PrepareCommand(commandLine, logger, "") if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if runtime.GOOS == "windows" { @@ -124,7 +124,7 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error { buf, err := command.Output() if err != nil { - return errors.New(i18n.WrapError(err).Error() + string(err.(*exec.ExitError).Stderr)) + return errors.New(errors.WithStack(err).Error() + string(err.(*exec.ExitError).Stderr)) } result := utils.NormalizeUTF8(buf) diff --git a/legacy/builder/read_file_and_store_in_context.go b/legacy/builder/read_file_and_store_in_context.go index 1d614becb53..cdd75896387 100644 --- a/legacy/builder/read_file_and_store_in_context.go +++ b/legacy/builder/read_file_and_store_in_context.go @@ -16,9 +16,9 @@ package builder import ( - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) type ReadFileAndStoreInContext struct { @@ -29,7 +29,7 @@ type ReadFileAndStoreInContext struct { func (s *ReadFileAndStoreInContext) Run(ctx *types.Context) error { bytes, err := s.FileToRead.ReadFile() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } *s.Target = string(bytes) diff --git a/legacy/builder/recipe_runner.go b/legacy/builder/recipe_runner.go index 781319c9e11..45be3218b78 100644 --- a/legacy/builder/recipe_runner.go +++ b/legacy/builder/recipe_runner.go @@ -22,10 +22,10 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" properties "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type RecipeByPrefixSuffixRunner struct { @@ -49,7 +49,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error { } _, _, err := builder_utils.ExecRecipe(ctx, properties, recipe, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } diff --git a/legacy/builder/set_custom_build_properties.go b/legacy/builder/set_custom_build_properties.go index e53c66caf59..088ee511263 100644 --- a/legacy/builder/set_custom_build_properties.go +++ b/legacy/builder/set_custom_build_properties.go @@ -16,9 +16,9 @@ package builder import ( - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type SetCustomBuildProperties struct{} @@ -27,7 +27,7 @@ func (s *SetCustomBuildProperties) Run(ctx *types.Context) error { buildProperties := ctx.BuildProperties customBuildProperties, err := properties.LoadFromSlice(ctx.CustomBuildProperties) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } buildProperties.Merge(customBuildProperties) diff --git a/legacy/builder/sketch_loader.go b/legacy/builder/sketch_loader.go index c6cec1d8008..276e5583f3d 100644 --- a/legacy/builder/sketch_loader.go +++ b/legacy/builder/sketch_loader.go @@ -19,12 +19,12 @@ import ( "sort" "strings" - paths "github.com/arduino/go-paths-helper" - "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" + "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" ) type SketchLoader struct{} @@ -38,11 +38,11 @@ func (s *SketchLoader) Run(ctx *types.Context) error { sketchLocation, err := sketchLocation.Abs() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } mainSketchStat, err := sketchLocation.Stat() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if mainSketchStat.IsDir() { sketchLocation = sketchLocation.Join(mainSketchStat.Name() + ".ino") @@ -52,7 +52,7 @@ func (s *SketchLoader) Run(ctx *types.Context) error { allSketchFilePaths, err := collectAllSketchFiles(sketchLocation.Parent()) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } logger := ctx.GetLogger() @@ -63,7 +63,7 @@ func (s *SketchLoader) Run(ctx *types.Context) error { sketch, err := makeSketch(sketchLocation, allSketchFilePaths, ctx.BuildPath, logger) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } ctx.SketchLocation = sketchLocation @@ -79,10 +79,10 @@ func collectAllSketchFiles(from *paths.Path) (paths.PathList, error) { rootExtensions := func(ext string) bool { return MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext] } err := utils.FindFilesInFolder(&filePaths, from.String(), rootExtensions, true /* recurse */) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } - return paths.NewPathList(filePaths...), i18n.WrapError(err) + return paths.NewPathList(filePaths...), errors.WithStack(err) } func makeSketch(sketchLocation *paths.Path, allSketchFilePaths paths.PathList, buildLocation *paths.Path, logger i18n.Logger) (*types.Sketch, error) { diff --git a/legacy/builder/test/helper.go b/legacy/builder/test/helper.go index 1df765f2be5..16cbe3d044b 100644 --- a/legacy/builder/test/helper.go +++ b/legacy/builder/test/helper.go @@ -28,7 +28,6 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" paths "github.com/arduino/go-paths-helper" - "github.com/go-errors/errors" "github.com/stretchr/testify/assert" ) @@ -57,10 +56,7 @@ func Abs(t *testing.T, rel *paths.Path) *paths.Path { func NoError(t *testing.T, err error, msgAndArgs ...interface{}) { if !assert.NoError(t, err, msgAndArgs...) { - switch err.(type) { - case *errors.Error: - fmt.Println(err.(*errors.Error).ErrorStack()) - } + fmt.Printf("%+v\n", err) // Outputs stack trace in case of wrapped error t.FailNow() } } diff --git a/legacy/builder/test/helper_tools_downloader.go b/legacy/builder/test/helper_tools_downloader.go index 24b13c14667..b4bca1614e8 100644 --- a/legacy/builder/test/helper_tools_downloader.go +++ b/legacy/builder/test/helper_tools_downloader.go @@ -30,11 +30,10 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/gohasissues" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/utils" "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" - "github.com/go-errors/errors" + "github.com/pkg/errors" ) var hardwareFolder = paths.New("downloaded_hardware") @@ -236,11 +235,11 @@ func downloadCores(cores []Core, index map[string]interface{}) error { for _, core := range cores { url, err := findCoreUrl(index, core) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackCore(core, url, hardwareFolder) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } return nil @@ -250,11 +249,11 @@ func downloadBoardManagerCores(cores []Core, index map[string]interface{}) error for _, core := range cores { url, err := findCoreUrl(index, core) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackBoardManagerCore(core, url, boardManagerFolder) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } return nil @@ -287,11 +286,11 @@ func downloadTools(tools []Tool, index map[string]interface{}) error { for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackTool(tool, url, toolsFolder, true) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -305,7 +304,7 @@ func downloadToolsMultipleVersions(tools []Tool, index map[string]interface{}) e if !toolAlreadyDownloadedAndUnpacked(toolsFolder, tool) { if toolsFolder.Join(tool.Name).Exist() { if err := toolsFolder.Join(tool.Name).RemoveAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } @@ -314,11 +313,11 @@ func downloadToolsMultipleVersions(tools []Tool, index map[string]interface{}) e for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackTool(tool, url, toolsFolder, false) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -331,11 +330,11 @@ func downloadBoardsManagerTools(tools []Tool, index map[string]interface{}) erro for _, tool := range tools { url, err := findToolUrl(index, tool, host) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackBoardsManagerTool(tool, url, boardManagerFolder) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -359,7 +358,7 @@ func allCoresAlreadyDownloadedAndUnpacked(targetPath *paths.Path, cores []Core) for _, core := range cores { alreadyDownloaded, err := coreAlreadyDownloadedAndUnpacked(targetPath, core) if err != nil { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } if !alreadyDownloaded { return false, nil @@ -376,12 +375,12 @@ func coreAlreadyDownloadedAndUnpacked(targetPath *paths.Path, core Core) (bool, } platform, err := properties.LoadFromPath(corePath.Join("platform.txt")) if err != nil { - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } if core.Version != platform.Get("version") { err := corePath.RemoveAll() - return false, i18n.WrapError(err) + return false, errors.WithStack(err) } return true, nil @@ -438,19 +437,19 @@ func libraryAlreadyDownloadedAndUnpacked(targetPath *paths.Path, library Library func downloadAndUnpackCore(core Core, url string, targetPath *paths.Path) error { alreadyDownloaded, err := coreAlreadyDownloadedAndUnpacked(targetPath, core) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } if alreadyDownloaded { return nil } if err := targetPath.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer unpackFolder.RemoveAll() @@ -459,26 +458,26 @@ func downloadAndUnpackCore(core Core, url string, targetPath *paths.Path) error if corePath.Exist() { if err := corePath.RemoveAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } if len(files) == 1 && files[0].IsDir() { if err := packagerPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = copyRecursive(unpackFolder.Join(files[0].Name()), targetPath.Join(core.Maintainer, core.Arch)) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else { if err := targetPath.Join(core.Maintainer, core.Arch).MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { err = copyRecursive(unpackFolder.Join(file.Name()), targetPath.Join(core.Maintainer, core.Arch, file.Name())) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } @@ -492,38 +491,38 @@ func downloadAndUnpackBoardManagerCore(core Core, url string, targetPath *paths. } if err := targetPath.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer unpackFolder.RemoveAll() corePath := targetPath.Join(core.Maintainer, "hardware", core.Arch) if corePath.Exist() { if err := corePath.RemoveAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } if len(files) == 1 && files[0].IsDir() { if err := corePath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = copyRecursive(unpackFolder.Join(files[0].Name()), corePath.Join(core.Version)) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else { if err := corePath.Join(core.Version).MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { err = copyRecursive(unpackFolder.Join(file.Name()), corePath.Join(core.Version, file.Name())) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } @@ -537,31 +536,31 @@ func downloadAndUnpackBoardsManagerTool(tool Tool, url string, targetPath *paths } if err := targetPath.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer unpackFolder.RemoveAll() if len(files) == 1 && files[0].IsDir() { if err := targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name).MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = copyRecursive(unpackFolder.Join(files[0].Name()), targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version)) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else { if err := targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version).MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { err = copyRecursive(unpackFolder.Join(file.Name()), targetPath.Join(tool.Package, constants.FOLDER_TOOLS, tool.Name, tool.Version, file.Name())) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } @@ -575,12 +574,12 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath *paths.Path, delete } if err := targetPath.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer unpackFolder.RemoveAll() @@ -588,27 +587,27 @@ func downloadAndUnpackTool(tool Tool, url string, targetPath *paths.Path, delete if deleteIfMissing { if toolPath.Exist() { if err := toolPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } if len(files) == 1 && files[0].IsDir() { if err := toolPath.MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = copyRecursive(unpackFolder.Join(files[0].Name()), toolPath.Join(tool.Version)) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else { if err := toolPath.Join(tool.Version).MkdirAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { err = copyRecursive(unpackFolder.Join(file.Name()), toolPath.Join(tool.Version, file.Name())) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } @@ -621,7 +620,7 @@ func downloadAndUnpack(url string) (*paths.Path, []os.FileInfo, error) { unpackFolder, err := paths.MkTempDir("", "arduino-builder-tool") if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } urlParts := strings.Split(url, "/") @@ -630,12 +629,12 @@ func downloadAndUnpack(url string) (*paths.Path, []os.FileInfo, error) { res, err := http.Get(url) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } bytes, err := ioutil.ReadAll(res.Body) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } res.Body.Close() @@ -645,7 +644,7 @@ func downloadAndUnpack(url string) (*paths.Path, []os.FileInfo, error) { out, err := cmd.CombinedOutput() if err != nil { fmt.Println(string(out)) - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } if len(out) > 0 { fmt.Println(string(out)) @@ -655,7 +654,7 @@ func downloadAndUnpack(url string) (*paths.Path, []os.FileInfo, error) { files, err := gohasissues.ReadDir(unpackFolder.String()) if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } return unpackFolder, files, nil @@ -727,11 +726,11 @@ func downloadLibraries(libraries []Library, index map[string]interface{}) error for _, library := range libraries { url, err := findLibraryUrl(index, library) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = downloadAndUnpackLibrary(library, url, librariesFolder) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } @@ -759,25 +758,25 @@ func downloadAndUnpackLibrary(library Library, url string, targetPath *paths.Pat } if err := targetPath.ToAbs(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } unpackFolder, files, err := downloadAndUnpack(url) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer unpackFolder.RemoveAll() libPath := targetPath.Join(strings.Replace(library.Name, " ", "_", -1)) if libPath.Exist() { if err := libPath.RemoveAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } err = copyRecursive(unpackFolder.Join(files[0].Name()), libPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } return nil @@ -791,42 +790,42 @@ func copyRecursive(from, to *paths.Path) error { rel, err := filepath.Rel(from.String(), currentPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } targetPath := filepath.Join(to.String(), rel) if info.IsDir() { err := os.MkdirAll(targetPath, info.Mode()) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else if info.Mode().IsRegular() { fromFile, err := os.Open(currentPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer fromFile.Close() targetFile, err := os.Create(targetPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } defer targetFile.Close() _, err = io.Copy(targetFile, fromFile) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } err = os.Chmod(targetPath, info.Mode()) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else if info.Mode()&os.ModeSymlink == os.ModeSymlink { linkedFile, err := os.Readlink(currentPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } fromFile := filepath.Join(filepath.Dir(targetPath), linkedFile) err = os.Symlink(fromFile, targetPath) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } else { return errors.Errorf("unable to copy file " + currentPath) @@ -835,5 +834,5 @@ func copyRecursive(from, to *paths.Path) error { return nil } err := gohasissues.Walk(from.String(), copyFunc) - return i18n.WrapError(err) + return errors.WithStack(err) } diff --git a/legacy/builder/unused_compiled_libraries_remover.go b/legacy/builder/unused_compiled_libraries_remover.go index 3e8c84b0e28..595ce91302e 100644 --- a/legacy/builder/unused_compiled_libraries_remover.go +++ b/legacy/builder/unused_compiled_libraries_remover.go @@ -17,9 +17,9 @@ package builder import ( "github.com/arduino/arduino-cli/arduino/libraries" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/arduino-cli/legacy/builder/utils" + "github.com/pkg/errors" ) type UnusedCompiledLibrariesRemover struct{} @@ -35,13 +35,13 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error { files, err := librariesBuildPath.ReadDir() if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { if file.IsDir() { if !utils.SliceContains(libraryNames, file.Base()) { if err := file.RemoveAll(); err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } } } diff --git a/legacy/builder/utils/utils.go b/legacy/builder/utils/utils.go index c781a9960da..d58d0e997a6 100644 --- a/legacy/builder/utils/utils.go +++ b/legacy/builder/utils/utils.go @@ -35,6 +35,7 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" paths "github.com/arduino/go-paths-helper" + "github.com/pkg/errors" "golang.org/x/text/transform" "golang.org/x/text/unicode/norm" ) @@ -100,7 +101,7 @@ type filterFiles func([]os.FileInfo) []os.FileInfo func ReadDirFiltered(folder string, fn filterFiles) ([]os.FileInfo, error) { files, err := gohasissues.ReadDir(folder) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } return fn(files), nil } @@ -209,7 +210,7 @@ type argFilterFunc func(int, string, []string) bool func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger, relativePath string) (*exec.Cmd, error) { parts, err := ParseCommandLine(pattern, logger) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } command := parts[0] parts = parts[1:] @@ -301,7 +302,7 @@ func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int) err := command.Start() if err != nil { - return nil, nil, i18n.WrapError(err) + return nil, nil, errors.WithStack(err) } err = command.Wait() @@ -314,7 +315,7 @@ func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int) errbytes = buf.Bytes() } - return outbytes, errbytes, i18n.WrapError(err) + return outbytes, errbytes, errors.WithStack(err) } func AbsolutizePaths(files []string) ([]string, error) { @@ -324,7 +325,7 @@ func AbsolutizePaths(files []string) ([]string, error) { } absFile, err := filepath.Abs(file) if err != nil { - return nil, i18n.WrapError(err) + return nil, errors.WithStack(err) } files[idx] = absFile } diff --git a/legacy/builder/wipeout_build_path_if_build_options_changed.go b/legacy/builder/wipeout_build_path_if_build_options_changed.go index 7b1ff279665..d00d282fbc2 100644 --- a/legacy/builder/wipeout_build_path_if_build_options_changed.go +++ b/legacy/builder/wipeout_build_path_if_build_options_changed.go @@ -22,9 +22,9 @@ import ( "github.com/arduino/arduino-cli/legacy/builder/builder_utils" "github.com/arduino/arduino-cli/legacy/builder/constants" "github.com/arduino/arduino-cli/legacy/builder/gohasissues" - "github.com/arduino/arduino-cli/legacy/builder/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" properties "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" ) type WipeoutBuildPathIfBuildOptionsChanged struct{} @@ -71,7 +71,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { buildPath := ctx.BuildPath files, err := gohasissues.ReadDir(buildPath.String()) if err != nil { - return i18n.WrapError(err) + return errors.WithStack(err) } for _, file := range files { buildPath.Join(file.Name()).RemoveAll()