Skip to content

Commit 8252a8e

Browse files
authored
[skip changelog] Remove legacy errors handling (#624)
* legacy: use github.com/pkg/errors for error handling * legacy: updated ErrrofWithLogger to use github.com/pkg/errors * legacy: removed use of github.com/go-errors/errors in test helpers * legacy: removed github.com/go-errors/errors from deps
1 parent 79bed42 commit 8252a8e

37 files changed

+245
-271
lines changed

Diff for: go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 // indirect
1717
github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 // indirect
1818
github.com/fsnotify/fsnotify v1.4.7
19-
github.com/go-errors/errors v1.0.1
2019
github.com/gofrs/uuid v3.2.0+incompatible
2120
github.com/golang/protobuf v1.3.3
2221
github.com/h2non/filetype v1.0.8 // indirect
@@ -27,7 +26,7 @@ require (
2726
github.com/mattn/go-runewidth v0.0.2 // indirect
2827
github.com/miekg/dns v1.0.5 // indirect
2928
github.com/oleksandr/bonjour v0.0.0-20160508152359-5dcf00d8b228 // indirect
30-
github.com/pkg/errors v0.8.1
29+
github.com/pkg/errors v0.9.1
3130
github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583
3231
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
3332
github.com/schollz/closestmatch v2.1.0+incompatible

Diff for: go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5/go.mod h1:BEUDl7
5454
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
5555
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
5656
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
57-
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
58-
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
5957
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
6058
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
6159
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
136134
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
137135
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
138136
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
139-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
140-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
137+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
138+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
141139
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
142140
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
143141
github.com/pmylund/sortutil v0.0.0-20120526081524-abeda66eb583 h1:ogHi8YLNeIxABOaH6UgtbwkODheuAK+ErP8gWXYQVj0=

Diff for: legacy/builder/add_additional_entries_to_context.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package builder
1818
import (
1919
"github.com/arduino/arduino-cli/arduino/cores"
2020
"github.com/arduino/arduino-cli/legacy/builder/constants"
21-
"github.com/arduino/arduino-cli/legacy/builder/i18n"
2221
"github.com/arduino/arduino-cli/legacy/builder/types"
22+
"github.com/pkg/errors"
2323
)
2424

2525
type AddAdditionalEntriesToContext struct{}
@@ -29,19 +29,19 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
2929
buildPath := ctx.BuildPath
3030
preprocPath, err := buildPath.Join(constants.FOLDER_PREPROC).Abs()
3131
if err != nil {
32-
return i18n.WrapError(err)
32+
return errors.WithStack(err)
3333
}
3434
sketchBuildPath, err := buildPath.Join(constants.FOLDER_SKETCH).Abs()
3535
if err != nil {
36-
return i18n.WrapError(err)
36+
return errors.WithStack(err)
3737
}
3838
librariesBuildPath, err := buildPath.Join("libraries").Abs()
3939
if err != nil {
40-
return i18n.WrapError(err)
40+
return errors.WithStack(err)
4141
}
4242
coreBuildPath, err := buildPath.Join(constants.FOLDER_CORE).Abs()
4343
if err != nil {
44-
return i18n.WrapError(err)
44+
return errors.WithStack(err)
4545
}
4646

4747
ctx.PreprocPath = preprocPath
@@ -53,7 +53,7 @@ func (*AddAdditionalEntriesToContext) Run(ctx *types.Context) error {
5353
if ctx.BuildCachePath != nil {
5454
coreBuildCachePath, err := ctx.BuildCachePath.Join(constants.FOLDER_CORE).Abs()
5555
if err != nil {
56-
return i18n.WrapError(err)
56+
return errors.WithStack(err)
5757
}
5858

5959
ctx.CoreBuildCachePath = coreBuildCachePath

Diff for: legacy/builder/builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
bldr "github.com/arduino/arduino-cli/arduino/builder"
2626
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2727
"github.com/arduino/arduino-cli/legacy/builder/constants"
28-
"github.com/arduino/arduino-cli/legacy/builder/i18n"
2928
"github.com/arduino/arduino-cli/legacy/builder/phases"
3029
"github.com/arduino/arduino-cli/legacy/builder/types"
3130
"github.com/arduino/arduino-cli/legacy/builder/utils"
31+
"github.com/pkg/errors"
3232
)
3333

3434
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
194194
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
195195
err := command.Run(ctx)
196196
if err != nil {
197-
return i18n.WrapError(err)
197+
return errors.WithStack(err)
198198
}
199199
}
200200
return nil

Diff for: legacy/builder/builder_utils/utils.go

+34-35
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/arduino/arduino-cli/legacy/builder/utils"
3131
"github.com/arduino/go-paths-helper"
3232
"github.com/arduino/go-properties-orderedmap"
33+
"github.com/pkg/errors"
3334
)
3435

3536
func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
@@ -48,18 +49,18 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
4849
func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
4950
objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
5051
if err != nil {
51-
return nil, i18n.WrapError(err)
52+
return nil, errors.WithStack(err)
5253
}
5354

5455
folders, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterDirs)
5556
if err != nil {
56-
return nil, i18n.WrapError(err)
57+
return nil, errors.WithStack(err)
5758
}
5859

5960
for _, folder := range folders {
6061
subFolderObjectFiles, err := CompileFilesRecursive(ctx, sourcePath.Join(folder.Name()), buildPath.Join(folder.Name()), buildProperties, includes)
6162
if err != nil {
62-
return nil, i18n.WrapError(err)
63+
return nil, errors.WithStack(err)
6364
}
6465
objectFiles.AddAll(subFolderObjectFiles)
6566
}
@@ -70,15 +71,15 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath
7071
func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
7172
sObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN)
7273
if err != nil {
73-
return nil, i18n.WrapError(err)
74+
return nil, errors.WithStack(err)
7475
}
7576
cObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".c", constants.RECIPE_C_PATTERN)
7677
if err != nil {
77-
return nil, i18n.WrapError(err)
78+
return nil, errors.WithStack(err)
7879
}
7980
cppObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".cpp", constants.RECIPE_CPP_PATTERN)
8081
if err != nil {
81-
return nil, i18n.WrapError(err)
82+
return nil, errors.WithStack(err)
8283
}
8384
objectFiles := paths.NewPathList()
8485
objectFiles.AddAll(sObjectFiles)
@@ -90,15 +91,15 @@ func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buil
9091
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) {
9192
sources, err := findFilesInFolder(sourcePath, extension, recurse)
9293
if err != nil {
93-
return nil, i18n.WrapError(err)
94+
return nil, errors.WithStack(err)
9495
}
9596
return compileFilesWithRecipe(ctx, sourcePath, sources, buildPath, buildProperties, includes, recipe)
9697
}
9798

9899
func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (paths.PathList, error) {
99100
files, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterFilesWithExtensions(extension))
100101
if err != nil {
101-
return nil, i18n.WrapError(err)
102+
return nil, errors.WithStack(err)
102103
}
103104
var sources paths.PathList
104105
for _, file := range files {
@@ -108,13 +109,13 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (
108109
if recurse {
109110
folders, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterDirs)
110111
if err != nil {
111-
return nil, i18n.WrapError(err)
112+
return nil, errors.WithStack(err)
112113
}
113114

114115
for _, folder := range folders {
115116
otherSources, err := findFilesInFolder(sourcePath.Join(folder.Name()), extension, recurse)
116117
if err != nil {
117-
return nil, i18n.WrapError(err)
118+
return nil, errors.WithStack(err)
118119
}
119120
sources = append(sources, otherSources...)
120121
}
@@ -126,7 +127,7 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (
126127
func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
127128
files, err := utils.ReadDirFiltered(sourcePath, utils.FilterFiles())
128129
if err != nil {
129-
return nil, i18n.WrapError(err)
130+
return nil, errors.WithStack(err)
130131
}
131132
var sources []string
132133
for _, file := range files {
@@ -136,15 +137,15 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
136137
if recurse {
137138
folders, err := utils.ReadDirFiltered(sourcePath, utils.FilterDirs)
138139
if err != nil {
139-
return nil, i18n.WrapError(err)
140+
return nil, errors.WithStack(err)
140141
}
141142

142143
for _, folder := range folders {
143144
if !utils.IsSCCSOrHiddenFile(folder) {
144145
// Skip SCCS directories as they do not influence the build and can be very large
145146
otherSources, err := findAllFilesInFolder(filepath.Join(sourcePath, folder.Name()), recurse)
146147
if err != nil {
147-
return nil, i18n.WrapError(err)
148+
return nil, errors.WithStack(err)
148149
}
149150
sources = append(sources, otherSources...)
150151
}
@@ -160,7 +161,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
160161
return objectFiles, nil
161162
}
162163
var objectFilesMux sync.Mutex
163-
var errors []error
164+
var errorsList []error
164165
var errorsMux sync.Mutex
165166

166167
ctx.Progress.Steps = ctx.Progress.Steps / float64(len(sources))
@@ -171,7 +172,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
171172
objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe)
172173
if err != nil {
173174
errorsMux.Lock()
174-
errors = append(errors, err)
175+
errorsList = append(errorsList, err)
175176
errorsMux.Unlock()
176177
} else {
177178
objectFilesMux.Lock()
@@ -199,7 +200,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
199200
// Feed jobs until error or done
200201
for _, source := range sources {
201202
errorsMux.Lock()
202-
gotError := len(errors) > 0
203+
gotError := len(errorsList) > 0
203204
errorsMux.Unlock()
204205
if gotError {
205206
break
@@ -208,9 +209,9 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
208209
}
209210
close(queue)
210211
wg.Wait()
211-
if len(errors) > 0 {
212+
if len(errorsList) > 0 {
212213
// output the first error
213-
return nil, i18n.WrapError(errors[0])
214+
return nil, errors.WithStack(errorsList[0])
214215
}
215216
objectFiles.Sort()
216217
return objectFiles, nil
@@ -224,25 +225,25 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
224225
properties.SetPath(constants.BUILD_PROPERTIES_SOURCE_FILE, source)
225226
relativeSource, err := sourcePath.RelTo(source)
226227
if err != nil {
227-
return nil, i18n.WrapError(err)
228+
return nil, errors.WithStack(err)
228229
}
229230
depsFile := buildPath.Join(relativeSource.String() + ".d")
230231
objectFile := buildPath.Join(relativeSource.String() + ".o")
231232

232233
properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)
233234
err = objectFile.Parent().MkdirAll()
234235
if err != nil {
235-
return nil, i18n.WrapError(err)
236+
return nil, errors.WithStack(err)
236237
}
237238

238239
objIsUpToDate, err := ObjFileIsUpToDate(ctx, source, objectFile, depsFile)
239240
if err != nil {
240-
return nil, i18n.WrapError(err)
241+
return nil, errors.WithStack(err)
241242
}
242243
if !objIsUpToDate {
243244
_, _, err = ExecRecipe(ctx, properties, recipe, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show)
244245
if err != nil {
245-
return nil, i18n.WrapError(err)
246+
return nil, errors.WithStack(err)
246247
}
247248
} else if ctx.Verbose {
248249
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
267268
sourceFile = sourceFile.Clean()
268269
sourceFileStat, err := sourceFile.Stat()
269270
if err != nil {
270-
return false, i18n.WrapError(err)
271+
return false, errors.WithStack(err)
271272
}
272273

273274
objectFile = objectFile.Clean()
@@ -279,7 +280,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
279280
}
280281
return false, nil
281282
} else {
282-
return false, i18n.WrapError(err)
283+
return false, errors.WithStack(err)
283284
}
284285
}
285286

@@ -292,7 +293,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
292293
}
293294
return false, nil
294295
} else {
295-
return false, i18n.WrapError(err)
296+
return false, errors.WithStack(err)
296297
}
297298
}
298299

@@ -311,7 +312,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
311312

312313
rows, err := dependencyFile.ReadFileAsLines()
313314
if err != nil {
314-
return false, i18n.WrapError(err)
315+
return false, errors.WithStack(err)
315316
}
316317

317318
rows = utils.Map(rows, removeEndingBackSlash)
@@ -346,7 +347,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
346347
// Ignore the error and trigger a full rebuild anyway
347348
if debugLevel >= 20 {
348349
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Failed to read: {0}", row)
349-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, i18n.WrapError(err).Error())
350+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, err.Error())
350351
}
351352
return false, nil
352353
}
@@ -454,9 +455,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
454455

455456
// something changed, rebuild the core archive
456457
if rebuildArchive {
457-
err = archiveFilePath.Remove()
458-
if err != nil {
459-
return nil, i18n.WrapError(err)
458+
if err := archiveFilePath.Remove(); err != nil {
459+
return nil, errors.WithStack(err)
460460
}
461461
} else {
462462
if ctx.Verbose {
@@ -472,9 +472,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
472472
properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath)
473473
properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)
474474

475-
_, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show)
476-
if err != nil {
477-
return nil, i18n.WrapError(err)
475+
if _, _, err := ExecRecipe(ctx, properties, constants.RECIPE_AR_PATTERN, false /* stdout */, utils.ShowIfVerbose /* stderr */, utils.Show); err != nil {
476+
return nil, errors.WithStack(err)
478477
}
479478
}
480479

@@ -485,7 +484,7 @@ func ExecRecipe(ctx *types.Context, buildProperties *properties.Map, recipe stri
485484
// See util.ExecCommand for stdout/stderr arguments
486485
command, err := PrepareCommandForRecipe(ctx, buildProperties, recipe, removeUnsetProperties)
487486
if err != nil {
488-
return nil, nil, i18n.WrapError(err)
487+
return nil, nil, errors.WithStack(err)
489488
}
490489

491490
return utils.ExecCommand(ctx, command, stdout, stderr)
@@ -514,7 +513,7 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map
514513

515514
command, err := utils.PrepareCommand(commandLine, logger, relativePath)
516515
if err != nil {
517-
return nil, i18n.WrapError(err)
516+
return nil, errors.WithStack(err)
518517
}
519518

520519
return command, nil

0 commit comments

Comments
 (0)