Skip to content

Commit c74b490

Browse files
committed
Improved error checks in profile loading
1 parent d486102 commit c74b490

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

internal/arduino/sketch/profiles.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@ func (p *ProfileRequiredPlatforms) AsYaml() string {
187187
return res
188188
}
189189

190+
func (p *ProfileRequiredPlatforms) UnmarshalYAML(unmarshal func(interface{}) error) error {
191+
_p := (*[]*ProfilePlatformReference)(p)
192+
if err := unmarshal(_p); err != nil {
193+
return err
194+
}
195+
requireSystemPlatform := (*_p)[0].RequireSystemInstalledPlatform()
196+
for _, platform := range *_p {
197+
if platform.RequireSystemInstalledPlatform() != requireSystemPlatform {
198+
return errors.New(i18n.Tr("all platforms in a profile must either require a specific version or not"))
199+
}
200+
}
201+
return nil
202+
}
203+
190204
// ProfileRequiredLibraries is a list of ProfileLibraryReference (libraries
191205
// required to build the sketch using this profile)
192206
type ProfileRequiredLibraries []*ProfileLibraryReference

internal/arduino/sketch/profiles_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ func TestProjectFileLoading(t *testing.T) {
4747
require.NoError(t, err)
4848
require.Equal(t, string(golden), proj.AsYaml())
4949
}
50+
{
51+
sketchProj := paths.New("testdata", "profiles", "bad_profile_1.yml")
52+
_, err := LoadProjectFile(sketchProj)
53+
require.Error(t, err)
54+
}
5055
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
profiles:
2+
tiny:
3+
notes: Invalid profile mixing versioned and non-versioned platforms.
4+
fqbn: attiny:avr:ATtinyX5:cpu=attiny85,clock=internal16
5+
platforms:
6+
- platform: attiny:avr
7+
platform_index_url: http://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
8+
- platform: arduino:avr (1.8.3)
9+

0 commit comments

Comments
 (0)