From 61aada48f8f5070dc43ace3d66f9b5a96d9b7eb6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 17 Jan 2024 16:40:34 +0100 Subject: [PATCH 1/2] Do not panic if a sketch' profile has a syntax error --- internal/arduino/sketch/profiles.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/arduino/sketch/profiles.go b/internal/arduino/sketch/profiles.go index 7ea5a7589b0..e1873c05ecd 100644 --- a/internal/arduino/sketch/profiles.go +++ b/internal/arduino/sketch/profiles.go @@ -72,7 +72,7 @@ func (p *Project) AsYaml() string { return res } -func (p *projectRaw) getProfiles() []*Profile { +func (p *projectRaw) getProfiles() ([]*Profile, error) { profiles := []*Profile{} for i, node := range p.ProfilesRaw.Content { if node.Tag != "!!str" { @@ -82,11 +82,11 @@ func (p *projectRaw) getProfiles() []*Profile { var profile Profile profile.Name = node.Value if err := p.ProfilesRaw.Content[i+1].Decode(&profile); err != nil { - panic(fmt.Sprintf("profiles parsing err: %v", err.Error())) + return nil, err } profiles = append(profiles, &profile) } - return profiles + return profiles, nil } // UnmarshalYAML decodes a Profiles section from YAML source. @@ -270,8 +270,12 @@ func LoadProjectFile(file *paths.Path) (*Project, error) { return nil, err } + profiles, err := raw.getProfiles() + if err != nil { + return nil, err + } return &Project{ - Profiles: raw.getProfiles(), + Profiles: profiles, DefaultProfile: raw.DefaultProfile, DefaultFqbn: raw.DefaultFqbn, DefaultPort: raw.DefaultPort, From 09dd8fcdcb2c32ae2fa6829b46e307ff66e4b888 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 17 Jan 2024 22:45:48 +0100 Subject: [PATCH 2/2] Removed redundant instance initialization --- commands/instances.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/commands/instances.go b/commands/instances.go index 3f8712de829..61f0725a0de 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -96,10 +96,6 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro if responseCallback == nil { responseCallback = func(r *rpc.InitResponse) {} } - reqInst := req.GetInstance() - if reqInst == nil { - return &cmderrors.InvalidInstanceError{} - } instance := req.GetInstance() if !instances.IsValid(instance) { return &cmderrors.InvalidInstanceError{}