Skip to content

Commit f4170da

Browse files
committed
Refactor: simplify init; check preconditions early
1 parent ae5febf commit f4170da

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

commands/service_profile_init.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020
"errors"
2121
"fmt"
22-
"sync"
2322

2423
"github.com/arduino/arduino-cli/commands/cmderrors"
2524
"github.com/arduino/arduino-cli/commands/internal/instances"
@@ -51,6 +50,10 @@ func (s *arduinoCoreServerImpl) InitProfile(ctx context.Context, req *rpc.InitPr
5150
if req.GetFqbn() == "" {
5251
return nil, &cmderrors.MissingFQBNError{}
5352
}
53+
fqbn, err := fqbn.Parse(req.GetFqbn())
54+
if err != nil {
55+
return nil, &cmderrors.InvalidFQBNError{Cause: err}
56+
}
5457

5558
// Check that the profile name is unique
5659
if profile, _ := sk.GetProfile(req.ProfileName); profile != nil {
@@ -61,18 +64,11 @@ func (s *arduinoCoreServerImpl) InitProfile(ctx context.Context, req *rpc.InitPr
6164
if err != nil {
6265
return nil, err
6366
}
64-
release = sync.OnceFunc(release)
6567
defer release()
66-
6768
if pme.Dirty() {
6869
return nil, &cmderrors.InstanceNeedsReinitialization{}
6970
}
7071

71-
fqbn, err := fqbn.Parse(req.GetFqbn())
72-
if err != nil {
73-
return nil, &cmderrors.InvalidFQBNError{Cause: err}
74-
}
75-
7672
// Automatically detect the target platform if it is installed on the user's machine
7773
_, targetPlatform, _, _, _, err := pme.ResolveFQBN(fqbn)
7874
if err != nil {

0 commit comments

Comments
 (0)