Skip to content

Handle library load failures #86

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 3 commits into from
Dec 2, 2020
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
19 changes: 12 additions & 7 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ import (

// LibraryPropertiesFormat checks for invalid library.properties format.
func LibraryPropertiesFormat() (result checkresult.Type, output string) {
if checkdata.LoadedLibrary() != nil && checkdata.LoadedLibrary().IsLegacy {
return checkresult.NotRun, ""
}

if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.Fail, checkdata.LibraryPropertiesLoadError().Error()
}

return checkresult.Pass, ""
}

// LibraryPropertiesMissing checks for presence of library.properties.
func LibraryPropertiesMissing() (result checkresult.Type, output string) {
if checkdata.LoadedLibrary() == nil {
return checkresult.NotRun, ""
}

if checkdata.LoadedLibrary().IsLegacy {
return checkresult.Fail, ""
}
Expand Down Expand Up @@ -768,11 +777,7 @@ func LibraryPropertiesDotALinkageFieldInvalid() (result checkresult.Type, output

// LibraryPropertiesDotALinkageFieldTrueWithFlatLayout checks whether a library using the "dot_a_linkage" feature has the required recursive layout type.
func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.Type, output string) {
if checkdata.LoadedLibrary() == nil {
return checkresult.NotRun, ""
}

if !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") {
if checkdata.LoadedLibrary() == nil || !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") {
return checkresult.NotRun, ""
}

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

// LibraryInvalid checks whether the provided path is a valid library.
func LibraryInvalid() (result checkresult.Type, output string) {
if library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) {
if checkdata.LoadedLibrary() != nil && library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) {
return checkresult.Pass, ""
}

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

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

Expand Down
4 changes: 4 additions & 0 deletions check/checkfunctions/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {

func TestLibraryPropertiesMissing(t *testing.T) {
testTables := []libraryCheckFunctionTestTable{
{"Invalid non-legacy", "InvalidLibraryProperties", checkresult.NotRun, ""},
{"Legacy", "Legacy", checkresult.Fail, ""},
{"Flat non-legacy", "Flat", checkresult.Pass, ""},
{"Recursive", "Recursive", checkresult.Pass, ""},
Expand All @@ -104,6 +105,7 @@ func TestRedundantLibraryProperties(t *testing.T) {
func TestLibraryPropertiesFormat(t *testing.T) {
testTables := []libraryCheckFunctionTestTable{
{"Invalid", "InvalidLibraryProperties", checkresult.Fail, ""},
{"Legacy", "Legacy", checkresult.NotRun, ""},
{"Valid", "Recursive", checkresult.Pass, ""},
}

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

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

func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
testTables := []libraryCheckFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
{"Flat", "Flat", checkresult.NotRun, ""},
{"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""},
{"Recursive without utility", "Recursive", checkresult.Pass, ""},
Expand Down
6 changes: 1 addition & 5 deletions project/library/libraryproperties/libraryproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import (

// Properties parses the library.properties from the given path and returns the data.
func Properties(libraryPath *paths.Path) (*properties.Map, error) {
libraryProperties, err := properties.Load(libraryPath.Join("library.properties").String())
if err != nil {
return nil, err
}
return libraryProperties, nil
return properties.SafeLoadFromPath(libraryPath.Join("library.properties"))
}

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