Skip to content

Commit 5134139

Browse files
committed
Improved error checks in profile loading
1 parent 0cc34e0 commit 5134139

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
@@ -186,6 +186,20 @@ func (p *ProfileRequiredPlatforms) AsYaml() string {
186186
return res
187187
}
188188

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