From 6726e4eaf05356d6cbd9e4803c5ecb5d9cff5533 Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 6 Nov 2025 13:16:13 +0100 Subject: [PATCH 1/8] feat: enhance AddSketchLibrary to update library index and log progress --- internal/orchestrator/sketch_libs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index d28c9ba8..c525b450 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -17,6 +17,9 @@ package orchestrator import ( "context" + "fmt" + "log/slog" + "time" "github.com/arduino/arduino-cli/commands" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -25,6 +28,8 @@ import ( "github.com/arduino/arduino-app-cli/internal/orchestrator/app" ) +const indexUpdateInterval = 1 * time.Second // TODO change to a better value + func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID, addDeps bool) ([]LibraryReleaseID, error) { srv := commands.NewArduinoCoreServer() var inst *rpc.Instance @@ -59,6 +64,19 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel if err != nil { return nil, err } + + // since the local library-index could be outofdate with respect the public library index, w + stream, res := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { + // TODO: LOG progress ? + slog.Error("progress", "msg", curr.String()) + }) + req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval)} + if err := srv.UpdateLibrariesIndex(req, stream); err != nil { + // TODO: is it correct to step the add of a library even is the library index could not be updated ? + return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) + } + slog.Error("OOOK Library index update", "index", res().GetLibrariesIndex()) + return f.Map(resp.GetAddedLibraries(), rpcProfileLibReferenceToLibReleaseID), nil } From e5a0282c999b5b578805d65156510b70807150cf Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 6 Nov 2025 15:14:24 +0100 Subject: [PATCH 2/8] fix: improve library index update handling in AddSketchLibrary --- internal/orchestrator/sketch_libs.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index c525b450..4772414e 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -48,6 +48,18 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel return nil, err } + // update the local library_index if it is older than a certain threshold, to ensure the library is found when added by the arduino-cli + stream, res := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { + // TODO: show log progres ? + slog.Debug("downloading library index", "progress", curr.Message) + }) + req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} + if err := srv.UpdateLibrariesIndex(req, stream); err != nil { + //TODO: only print a warn message instead of failing ?? The local-library could contain the lib even if the update fail + return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) + } + slog.Debug("Library index update", "status", res().GetLibrariesIndex().GetStatus()) + resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{ Instance: inst, SketchPath: app.MainSketchPath.String(), @@ -65,18 +77,6 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel return nil, err } - // since the local library-index could be outofdate with respect the public library index, w - stream, res := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { - // TODO: LOG progress ? - slog.Error("progress", "msg", curr.String()) - }) - req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval)} - if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - // TODO: is it correct to step the add of a library even is the library index could not be updated ? - return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) - } - slog.Error("OOOK Library index update", "index", res().GetLibrariesIndex()) - return f.Map(resp.GetAddedLibraries(), rpcProfileLibReferenceToLibReleaseID), nil } From 38b5c129524ca131d4459880932a02900bf4931c Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 6 Nov 2025 15:18:14 +0100 Subject: [PATCH 3/8] fix: improve error handling in AddSketchLibrary by logging warnings instead of failing on library index update --- internal/orchestrator/sketch_libs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index 4772414e..74bc7aa5 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -50,12 +50,11 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel // update the local library_index if it is older than a certain threshold, to ensure the library is found when added by the arduino-cli stream, res := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { - // TODO: show log progres ? slog.Debug("downloading library index", "progress", curr.Message) }) req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - //TODO: only print a warn message instead of failing ?? The local-library could contain the lib even if the update fail + //TODO: only print a warn message instead of failing ? in order to avoid blocking the user to instal lthe lib in case it is present into the local index return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) } slog.Debug("Library index update", "status", res().GetLibrariesIndex().GetStatus()) From 3d622cfc2167cd60020b5d7211537f8aa16aa8d1 Mon Sep 17 00:00:00 2001 From: dido18 Date: Thu, 6 Nov 2025 16:57:10 +0100 Subject: [PATCH 4/8] fix: extend library index update interval to 60 seconds for improved performance --- internal/orchestrator/sketch_libs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index 74bc7aa5..236a9378 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -28,7 +28,7 @@ import ( "github.com/arduino/arduino-app-cli/internal/orchestrator/app" ) -const indexUpdateInterval = 1 * time.Second // TODO change to a better value +const indexUpdateInterval = 60 * time.Second func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID, addDeps bool) ([]LibraryReleaseID, error) { srv := commands.NewArduinoCoreServer() @@ -54,7 +54,7 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel }) req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - //TODO: only print a warn message instead of failing ? in order to avoid blocking the user to instal lthe lib in case it is present into the local index + // TODO: only print a warn message instead of failing ? in order to avoid blocking the user to install the lib in case it is present into the local index return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) } slog.Debug("Library index update", "status", res().GetLibrariesIndex().GetStatus()) From 4ef61452fcdb1d2e2220b7d1edca554bc4685961 Mon Sep 17 00:00:00 2001 From: dido18 Date: Fri, 7 Nov 2025 12:10:00 +0100 Subject: [PATCH 5/8] fix: update library index refresh interval to 10 minutes for improved performance --- internal/orchestrator/sketch_libs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index 236a9378..cdfc11cf 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -28,7 +28,7 @@ import ( "github.com/arduino/arduino-app-cli/internal/orchestrator/app" ) -const indexUpdateInterval = 60 * time.Second +const indexUpdateInterval = 10 * time.Minute func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID, addDeps bool) ([]LibraryReleaseID, error) { srv := commands.NewArduinoCoreServer() @@ -54,7 +54,6 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel }) req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - // TODO: only print a warn message instead of failing ? in order to avoid blocking the user to install the lib in case it is present into the local index return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) } slog.Debug("Library index update", "status", res().GetLibrariesIndex().GetStatus()) From 9efb92a576e632b2b9505f99142f82b83ce5982b Mon Sep 17 00:00:00 2001 From: dido18 Date: Fri, 7 Nov 2025 14:46:00 +0100 Subject: [PATCH 6/8] fix: improve error handling in AddSketchLibrary by logging warnings for library index update failures --- internal/orchestrator/sketch_libs.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index cdfc11cf..cf2f1005 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -17,7 +17,6 @@ package orchestrator import ( "context" - "fmt" "log/slog" "time" @@ -48,15 +47,15 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel return nil, err } - // update the local library_index if it is older than a certain threshold, to ensure the library is found when added by the arduino-cli - stream, res := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { - slog.Debug("downloading library index", "progress", curr.Message) + stream, _ := commands.UpdateLibrariesIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) { + slog.Debug("downloading library index", "progress", curr.GetMessage()) }) + // update the local library index after a certain time, to avoid if a library is added to the sketch but the local library index is not update, the compile can fail (because the lib is not found) req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - return []LibraryReleaseID{}, fmt.Errorf("error updating library index: %v", err) + // ignore the error because a missing connection should not stop the user from adding a library. + slog.Warn("error updating library index", slog.String("error", err.Error())) } - slog.Debug("Library index update", "status", res().GetLibrariesIndex().GetStatus()) resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{ Instance: inst, From 4dd6ee618128fecfaba80844184a8321f7faf2ad Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 7 Nov 2025 17:16:32 +0100 Subject: [PATCH 7/8] Update internal/orchestrator/sketch_libs.go Co-authored-by: Luca Rinaldi --- internal/orchestrator/sketch_libs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index cf2f1005..25f884be 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -54,7 +54,7 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { // ignore the error because a missing connection should not stop the user from adding a library. - slog.Warn("error updating library index", slog.String("error", err.Error())) + slog.Warn("error updating library index, skipping", slog.String("error", err.Error())) } resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{ From ebc9d124902a533223bc21b28a0a48231e3d92d8 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 7 Nov 2025 17:16:40 +0100 Subject: [PATCH 8/8] Update internal/orchestrator/sketch_libs.go Co-authored-by: Luca Rinaldi --- internal/orchestrator/sketch_libs.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/orchestrator/sketch_libs.go b/internal/orchestrator/sketch_libs.go index 25f884be..3ef3b7ff 100644 --- a/internal/orchestrator/sketch_libs.go +++ b/internal/orchestrator/sketch_libs.go @@ -53,7 +53,6 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel // update the local library index after a certain time, to avoid if a library is added to the sketch but the local library index is not update, the compile can fail (because the lib is not found) req := &rpc.UpdateLibrariesIndexRequest{Instance: inst, UpdateIfOlderThanSecs: int64(indexUpdateInterval.Seconds())} if err := srv.UpdateLibrariesIndex(req, stream); err != nil { - // ignore the error because a missing connection should not stop the user from adding a library. slog.Warn("error updating library index, skipping", slog.String("error", err.Error())) }