Skip to content

Commit 9a08fec

Browse files
authored
fix: library loading errors genereates unneeded compile failures (arduino#2139)
1 parent fe91ec6 commit 9a08fec

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

commands/instances.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
458458
}
459459
}
460460

461-
for _, err := range lm.RescanLibraries() {
462-
s := status.Newf(codes.FailedPrecondition, tr("Loading libraries: %v"), err)
463-
responseError(s)
461+
for _, status := range lm.RescanLibraries() {
462+
logrus.WithError(status.Err()).Warnf("Error loading library")
463+
// TODO: report as warning: responseError(err)
464464
}
465465

466466
// Refreshes the locale used, this will change the

internal/integrationtest/compile_3/compile_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package compile_test
1717

1818
import (
19+
"fmt"
1920
"testing"
2021

2122
"github.com/arduino/arduino-cli/internal/integrationtest"
@@ -154,3 +155,28 @@ func TestCompileRelativeLibraryPath(t *testing.T) {
154155
require.Contains(t, string(stdout), "Used: "+FooLib.String())
155156
require.Contains(t, string(stdout), "Not used: "+cli.SketchbookDir().Join("libraries", "FooLib").String())
156157
}
158+
159+
func TestCompileWithInvalidLibrary(t *testing.T) {
160+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
161+
defer env.CleanUp()
162+
163+
_, _, err := cli.Run("core", "install", "arduino:avr")
164+
require.NoError(t, err)
165+
166+
// Make an empty library
167+
emptyLibPath := cli.SketchbookDir().Join("libraries", "EmptyLib")
168+
require.NoError(t, emptyLibPath.MkdirAll())
169+
170+
// prepare sketch
171+
sketch, err := paths.New("testdata", "bare_minimum").Abs()
172+
require.NoError(t, err)
173+
174+
// Compile must succeed
175+
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", sketch.String())
176+
require.NoError(t, err)
177+
178+
// Verbose compile must report invalid library
179+
_, stderr, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
180+
require.NoError(t, err)
181+
require.Contains(t, string(stderr), fmt.Sprintf("loading library from %s: invalid library: no header files found", emptyLibPath))
182+
}

legacy/builder/libraries_loader.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
5656
lm.AddLibrariesDir(folder, libraries.User)
5757
}
5858

59-
if errs := lm.RescanLibraries(); len(errs) > 0 {
59+
for _, status := range lm.RescanLibraries() {
6060
// With the refactoring of the initialization step of the CLI we changed how
6161
// errors are returned when loading platforms and libraries, that meant returning a list of
6262
// errors instead of a single one to enhance the experience for the user.
6363
// I have no intention right now to start a refactoring of the legacy package too, so
6464
// here's this shitty solution for now.
6565
// When we're gonna refactor the legacy package this will be gone.
66-
return errors.WithStack(errs[0].Err())
66+
if ctx.Verbose {
67+
ctx.Warn(status.Message())
68+
}
6769
}
6870

6971
for _, dir := range ctx.LibraryDirs {

0 commit comments

Comments
 (0)