Skip to content

Commit 7271e0a

Browse files
Fix NewSketch crash when directories.user is not set (#2862)
* integrationtest: add dameon NewSketch tests * commands: fix panic when calling `NewSketch` with empty directories.user We were calling directly a function that lookup for user definied settings. In case an user did not set explictly the directory it would return an empty string causing a panic. Instead we should have used a dedicated function `UserDir` that uses a fallback the default directories.user
1 parent b9edb78 commit 7271e0a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Diff for: commands/service_sketch_new.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) NewSketch(ctx context.Context, req *rpc.NewSketc
4848
if len(req.GetSketchDir()) > 0 {
4949
sketchesDir = req.GetSketchDir()
5050
} else {
51-
sketchesDir = s.settings.GetString("directories.User")
51+
sketchesDir = s.settings.UserDir().String()
5252
}
5353

5454
if err := validateSketchName(req.GetSketchName()); err != nil {

Diff for: internal/integrationtest/arduino-cli.go

+11
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,14 @@ func (inst *ArduinoCLIInstance) BoardIdentify(ctx context.Context, props map[str
710710
resp, err := inst.cli.daemonClient.BoardIdentify(ctx, req)
711711
return resp, err
712712
}
713+
714+
// NewSketch calls the "NewSketch" gRPC method.
715+
func (inst *ArduinoCLIInstance) NewSketch(ctx context.Context, sketchName, sketchDir string, overwrite bool) (*commands.NewSketchResponse, error) {
716+
req := &commands.NewSketchRequest{
717+
SketchName: sketchName,
718+
SketchDir: sketchDir,
719+
Overwrite: overwrite,
720+
}
721+
logCallf(">>> NewSketch(%+v)\n", req)
722+
return inst.cli.daemonClient.NewSketch(ctx, req)
723+
}

Diff for: internal/integrationtest/daemon/daemon_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,22 @@ func TestDaemonUserAgent(t *testing.T) {
614614
}
615615
}
616616

617+
func TestDaemonCreateSketch(t *testing.T) {
618+
// https://github.com/arduino/arduino-cli/issues/2861
619+
620+
env, cli := integrationtest.CreateEnvForDaemon(t)
621+
defer env.CleanUp()
622+
623+
grpcInst := cli.Create()
624+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
625+
fmt.Printf("INIT> %v\n", ir.GetMessage())
626+
}))
627+
628+
sketchName := "test_sketch.ino"
629+
_, err := grpcInst.NewSketch(context.Background(), sketchName, "", false)
630+
require.NoError(t, err)
631+
}
632+
617633
func analyzeUpdateIndexClient(t *testing.T, cl commands.ArduinoCoreService_UpdateIndexClient) (map[string]*commands.DownloadProgressEnd, error) {
618634
analyzer := NewDownloadProgressAnalyzer(t)
619635
for {

0 commit comments

Comments
 (0)