Skip to content

Remove legacy errors handling #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
12 changes: 6 additions & 6 deletions legacy/builder/add_additional_entries_to_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
69 changes: 34 additions & 35 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -90,15 +91,15 @@ 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)
}

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 {
Expand All @@ -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...)
}
Expand All @@ -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 {
Expand All @@ -136,15 +137,15 @@ 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 {
if !utils.IsSCCSOrHiddenFile(folder) {
// 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...)
}
Expand All @@ -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))
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -224,25 +225,25 @@ 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")

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)
Expand All @@ -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()
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading