Skip to content

Commit 8f8172b

Browse files
committed
Small refactoring, no code change
1 parent c304d9b commit 8f8172b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

internal/arduino/sketch/profiles.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,23 @@ type ProfileLibraryReference struct {
356356
// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
357357
func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) error) error {
358358
var dataMap map[string]any
359+
var data string
359360
if err := unmarshal(&dataMap); err == nil {
360-
if installDir, ok := dataMap["dir"]; !ok {
361-
return errors.New(i18n.Tr("invalid library reference: %s", dataMap))
362-
} else if installDir, ok := installDir.(string); !ok {
363-
return fmt.Errorf("%s: %s", i18n.Tr("invalid library reference: %s"), dataMap)
361+
if installDir, ok := dataMap["dir"]; ok {
362+
if installDir, ok := installDir.(string); !ok {
363+
return fmt.Errorf("%s: %s", i18n.Tr("invalid library reference: %s"), dataMap)
364+
} else {
365+
l.InstallDir = paths.New(installDir)
366+
l.Library = l.InstallDir.Base()
367+
return nil
368+
}
364369
} else {
365-
l.InstallDir = paths.New(installDir)
366-
l.Library = l.InstallDir.Base()
367-
return nil
370+
return errors.New(i18n.Tr("invalid library reference: %s", dataMap))
368371
}
369-
}
370-
371-
var data string
372-
if err := unmarshal(&data); err != nil {
372+
} else if err := unmarshal(&data); err != nil {
373373
return err
374374
}
375+
375376
if libName, libVersion, ok := parseNameAndVersion(data); !ok {
376377
return fmt.Errorf("%s %s", i18n.Tr("invalid library directive:"), data)
377378
} else if v, err := semver.Parse(libVersion); err != nil {

0 commit comments

Comments
 (0)