Improve error messages for external config files.

This commit is contained in:
Federico Builes
2022-11-15 07:45:29 +01:00
parent 30d5821115
commit 0a055a6a13
+16 -3
View File
@@ -80,7 +80,13 @@ function validateLicenses(
if (licenses === undefined) { if (licenses === undefined) {
return return
} }
const invalid_licenses = licenses.filter(license => !isSPDXValid(license))
let invalid_licenses
try {
invalid_licenses = licenses.filter(license => !isSPDXValid(license))
} catch (error) {
throw new Error(`Error validating license(s): ${error.message}`)
}
if (invalid_licenses.length > 0) { if (invalid_licenses.length > 0) {
throw new Error( throw new Error(
@@ -113,8 +119,8 @@ async function readConfigFile(
} }
return parseConfigFile(data) return parseConfigFile(data)
} catch (error) { } catch (error) {
core.debug(error as string) core.debug((error as Error).message)
throw new Error('Unable to fetch config file') throw new Error('Unable to fetch or parse config file')
} }
} }
@@ -123,8 +129,15 @@ function parseConfigFile(configData: string): ConfigurationOptionsPartial {
const data = YAML.parse(configData) const data = YAML.parse(configData)
for (const key of Object.keys(data)) { for (const key of Object.keys(data)) {
if (key === 'allow-licenses' || key === 'deny-licenses') { if (key === 'allow-licenses' || key === 'deny-licenses') {
const licenses = data[key]
// handle the case where the user has a singe or invalid license
// in the config file
if (typeof licenses === 'string') {
validateLicenses(key, [licenses])
} else {
validateLicenses(key, data[key]) validateLicenses(key, data[key])
} }
}
// get rid of the ugly dashes from the actions conventions // get rid of the ugly dashes from the actions conventions
if (key.includes('-')) { if (key.includes('-')) {
data[key.replace(/-/g, '_')] = data[key] data[key.replace(/-/g, '_')] = data[key]