Skip to content

Commit 3495fff

Browse files
committed
sketch.GetProfile returns an error if profile is not found
1 parent 95753fc commit 3495fff

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

commands/instances.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
142142
if err != nil {
143143
return &cmderrors.InvalidArgumentError{Cause: err}
144144
}
145-
profile = sk.GetProfile(req.GetProfile())
146-
if profile == nil {
147-
return &cmderrors.UnknownProfileError{Profile: req.GetProfile()}
145+
profile, err := sk.GetProfile(req.GetProfile())
146+
if err != nil {
147+
return err
148148
}
149149
responseCallback(&rpc.InitResponse{
150150
Message: &rpc.InitResponse_Profile{

commands/sketch/load.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
5858
}
5959

6060
defaultProfileResp := &rpc.SketchProfile{}
61-
defaultProfile := sk.GetProfile(sk.Project.DefaultProfile)
62-
if defaultProfile != nil {
61+
defaultProfile, err := sk.GetProfile(sk.Project.DefaultProfile)
62+
if err == nil {
6363
defaultProfileResp.Name = defaultProfile.Name
6464
defaultProfileResp.Fqbn = defaultProfile.FQBN
6565
}

internal/arduino/sketch/sketch.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sort"
2424
"strings"
2525

26+
"github.com/arduino/arduino-cli/commands/cmderrors"
2627
"github.com/arduino/arduino-cli/internal/arduino/globals"
2728
"github.com/arduino/arduino-cli/internal/i18n"
2829
"github.com/arduino/go-paths-helper"
@@ -180,15 +181,14 @@ func (s *Sketch) supportedFiles() (*paths.PathList, error) {
180181
return &files, nil
181182
}
182183

183-
// GetProfile returns the requested profile or nil if the profile
184-
// is not found.
185-
func (s *Sketch) GetProfile(profileName string) *Profile {
184+
// GetProfile returns the requested profile or an error if not found
185+
func (s *Sketch) GetProfile(profileName string) (*Profile, error) {
186186
for _, p := range s.Project.Profiles {
187187
if p.Name == profileName {
188-
return p
188+
return p, nil
189189
}
190190
}
191-
return nil
191+
return nil, &cmderrors.UnknownProfileError{Profile: profileName}
192192
}
193193

194194
// checkSketchCasing returns an error if the casing of the sketch folder and the main file are different.

0 commit comments

Comments
 (0)