Skip to content

Commit 83b63b7

Browse files
authored
Merge pull request #86 from arduino/per1234/handle-library-load-failures
Handle library load failures
2 parents 6dbedc6 + 98d8011 commit 83b63b7

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Diff for: check/checkfunctions/library.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,23 @@ import (
3838

3939
// LibraryPropertiesFormat checks for invalid library.properties format.
4040
func LibraryPropertiesFormat() (result checkresult.Type, output string) {
41+
if checkdata.LoadedLibrary() != nil && checkdata.LoadedLibrary().IsLegacy {
42+
return checkresult.NotRun, ""
43+
}
44+
4145
if checkdata.LibraryPropertiesLoadError() != nil {
4246
return checkresult.Fail, checkdata.LibraryPropertiesLoadError().Error()
4347
}
48+
4449
return checkresult.Pass, ""
4550
}
4651

4752
// LibraryPropertiesMissing checks for presence of library.properties.
4853
func LibraryPropertiesMissing() (result checkresult.Type, output string) {
54+
if checkdata.LoadedLibrary() == nil {
55+
return checkresult.NotRun, ""
56+
}
57+
4958
if checkdata.LoadedLibrary().IsLegacy {
5059
return checkresult.Fail, ""
5160
}
@@ -768,11 +777,7 @@ func LibraryPropertiesDotALinkageFieldInvalid() (result checkresult.Type, output
768777

769778
// LibraryPropertiesDotALinkageFieldTrueWithFlatLayout checks whether a library using the "dot_a_linkage" feature has the required recursive layout type.
770779
func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.Type, output string) {
771-
if checkdata.LoadedLibrary() == nil {
772-
return checkresult.NotRun, ""
773-
}
774-
775-
if !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") {
780+
if checkdata.LoadedLibrary() == nil || !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") {
776781
return checkresult.NotRun, ""
777782
}
778783

@@ -905,7 +910,7 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output
905910

906911
// LibraryInvalid checks whether the provided path is a valid library.
907912
func LibraryInvalid() (result checkresult.Type, output string) {
908-
if library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) {
913+
if checkdata.LoadedLibrary() != nil && library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) {
909914
return checkresult.Pass, ""
910915
}
911916

@@ -1120,7 +1125,7 @@ func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
11201125

11211126
// RecursiveLibraryWithUtilityFolder checks for presence of a `utility` subfolder in a recursive layout library.
11221127
func RecursiveLibraryWithUtilityFolder() (result checkresult.Type, output string) {
1123-
if checkdata.LoadedLibrary().Layout == libraries.FlatLayout {
1128+
if checkdata.LoadedLibrary() == nil || checkdata.LoadedLibrary().Layout == libraries.FlatLayout {
11241129
return checkresult.NotRun, ""
11251130
}
11261131

Diff for: check/checkfunctions/library_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {
8484

8585
func TestLibraryPropertiesMissing(t *testing.T) {
8686
testTables := []libraryCheckFunctionTestTable{
87+
{"Invalid non-legacy", "InvalidLibraryProperties", checkresult.NotRun, ""},
8788
{"Legacy", "Legacy", checkresult.Fail, ""},
8889
{"Flat non-legacy", "Flat", checkresult.Pass, ""},
8990
{"Recursive", "Recursive", checkresult.Pass, ""},
@@ -104,6 +105,7 @@ func TestRedundantLibraryProperties(t *testing.T) {
104105
func TestLibraryPropertiesFormat(t *testing.T) {
105106
testTables := []libraryCheckFunctionTestTable{
106107
{"Invalid", "InvalidLibraryProperties", checkresult.Fail, ""},
108+
{"Legacy", "Legacy", checkresult.NotRun, ""},
107109
{"Valid", "Recursive", checkresult.Pass, ""},
108110
}
109111

@@ -242,6 +244,7 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
242244

243245
func TestLibraryInvalid(t *testing.T) {
244246
testTables := []libraryCheckFunctionTestTable{
247+
{"Invalid library.properties", "InvalidLibraryProperties", checkresult.Fail, ""},
245248
{"Invalid flat layout", "FlatWithoutHeader", checkresult.Fail, ""},
246249
{"Invalid recursive layout", "RecursiveWithoutLibraryProperties", checkresult.Fail, ""},
247250
{"Valid library", "Recursive", checkresult.Pass, ""},
@@ -383,6 +386,7 @@ func TestIncorrectExtrasFolderNameCase(t *testing.T) {
383386

384387
func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
385388
testTables := []libraryCheckFunctionTestTable{
389+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
386390
{"Flat", "Flat", checkresult.NotRun, ""},
387391
{"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""},
388392
{"Recursive without utility", "Recursive", checkresult.Pass, ""},

Diff for: project/library/libraryproperties/libraryproperties.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ import (
2626

2727
// Properties parses the library.properties from the given path and returns the data.
2828
func Properties(libraryPath *paths.Path) (*properties.Map, error) {
29-
libraryProperties, err := properties.Load(libraryPath.Join("library.properties").String())
30-
if err != nil {
31-
return nil, err
32-
}
33-
return libraryProperties, nil
29+
return properties.SafeLoadFromPath(libraryPath.Join("library.properties"))
3430
}
3531

3632
var schemaObject = make(map[compliancelevel.Type]*jsonschema.Schema)

0 commit comments

Comments
 (0)