Skip to content

bugfix: do not panic if a sketch profile has a syntax error #2506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
12 changes: 8 additions & 4 deletions internal/arduino/sketch/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down