From 0a055a6a13291a89ed6cdfa62f5738ad3282af45 Mon Sep 17 00:00:00 2001 From: Federico Builes Date: Tue, 15 Nov 2022 07:45:29 +0100 Subject: [PATCH] Improve error messages for external config files. --- src/config.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index 9c097a9..956c455 100644 --- a/src/config.ts +++ b/src/config.ts @@ -80,7 +80,13 @@ function validateLicenses( if (licenses === undefined) { 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) { throw new Error( @@ -113,8 +119,8 @@ async function readConfigFile( } return parseConfigFile(data) } catch (error) { - core.debug(error as string) - throw new Error('Unable to fetch config file') + core.debug((error as Error).message) + throw new Error('Unable to fetch or parse config file') } } @@ -123,7 +129,14 @@ function parseConfigFile(configData: string): ConfigurationOptionsPartial { const data = YAML.parse(configData) for (const key of Object.keys(data)) { if (key === 'allow-licenses' || key === 'deny-licenses') { - validateLicenses(key, data[key]) + 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]) + } } // get rid of the ugly dashes from the actions conventions if (key.includes('-')) {