Throw an error if the config is the wrong type

This commit is contained in:
Josh Dales
2023-03-18 14:51:39 -04:00
parent fc5eb711b0
commit e4486e9ed9

View File

@@ -130,20 +130,22 @@ async function fetchContent(
function getLabelConfigMapFromObject( function getLabelConfigMapFromObject(
configObject: any configObject: any
): Map<string, MatchConfig[]> { ): Map<string, MatchConfig[]> {
const labelGlobs: Map<string, MatchConfig[]> = new Map(); const labelMap: Map<string, MatchConfig[]> = new Map();
for (const label in configObject) { for (const label in configObject) {
if (typeof configObject[label] === 'string') { const configOptions = configObject[label];
labelGlobs.set(label, [configObject[label]]); if (
} else if (configObject[label] instanceof Array) { !Array.isArray(configOptions) ||
labelGlobs.set(label, configObject[label]); !configOptions.every(opts => typeof opts === 'object')
} else { ) {
throw Error( throw Error(
`found unexpected type for label ${label} (should be string or array of globs)` `found unexpected type for label ${label} (should be array of config options)`
); );
} }
labelMap.set(label, configOptions);
} }
return labelGlobs; return labelMap;
} }
function toChangedFilesMatchConfig(config: any): ChangedFilesMatchConfig { function toChangedFilesMatchConfig(config: any): ChangedFilesMatchConfig {