Skip to content

Commit 96b411f

Browse files
authored
bugfix: do not panic if a sketch profile has a syntax error (#2506)
* Do not panic if a sketch' profile has a syntax error * Removed redundant instance initialization
1 parent 3ccdb9d commit 96b411f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: commands/instances.go

-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
9696
if responseCallback == nil {
9797
responseCallback = func(r *rpc.InitResponse) {}
9898
}
99-
reqInst := req.GetInstance()
100-
if reqInst == nil {
101-
return &cmderrors.InvalidInstanceError{}
102-
}
10399
instance := req.GetInstance()
104100
if !instances.IsValid(instance) {
105101
return &cmderrors.InvalidInstanceError{}

Diff for: internal/arduino/sketch/profiles.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (p *Project) AsYaml() string {
7272
return res
7373
}
7474

75-
func (p *projectRaw) getProfiles() []*Profile {
75+
func (p *projectRaw) getProfiles() ([]*Profile, error) {
7676
profiles := []*Profile{}
7777
for i, node := range p.ProfilesRaw.Content {
7878
if node.Tag != "!!str" {
@@ -82,11 +82,11 @@ func (p *projectRaw) getProfiles() []*Profile {
8282
var profile Profile
8383
profile.Name = node.Value
8484
if err := p.ProfilesRaw.Content[i+1].Decode(&profile); err != nil {
85-
panic(fmt.Sprintf("profiles parsing err: %v", err.Error()))
85+
return nil, err
8686
}
8787
profiles = append(profiles, &profile)
8888
}
89-
return profiles
89+
return profiles, nil
9090
}
9191

9292
// UnmarshalYAML decodes a Profiles section from YAML source.
@@ -270,8 +270,12 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
270270
return nil, err
271271
}
272272

273+
profiles, err := raw.getProfiles()
274+
if err != nil {
275+
return nil, err
276+
}
273277
return &Project{
274-
Profiles: raw.getProfiles(),
278+
Profiles: profiles,
275279
DefaultProfile: raw.DefaultProfile,
276280
DefaultFqbn: raw.DefaultFqbn,
277281
DefaultPort: raw.DefaultPort,

0 commit comments

Comments
 (0)