Merge pull request #22402 from backstage/freben/resolveInputData

improve `resolveInputData` error messaging
This commit is contained in:
Fredrik Adelöw
2024-01-20 15:31:36 +01:00
committed by GitHub
4 changed files with 19 additions and 5 deletions
@@ -615,8 +615,8 @@ describe('createAppNodeInstance', () => {
),
),
}),
).toThrow(
"Failed to instantiate extension 'app/test', input 'singleton' did not receive required extension data 'other' from extension 'app/test'",
).toThrowErrorMatchingInlineSnapshot(
`"Failed to instantiate extension 'app/test', extension 'app/test' could not be attached because its output data ('test', 'other') does not match what the input 'singleton' requires ('other')"`,
);
});
});
@@ -37,8 +37,17 @@ function resolveInputData(
return mapValues(dataMap, ref => {
const value = attachment.instance?.getData(ref);
if (value === undefined && !ref.config.optional) {
const expected = Object.values(dataMap)
.filter(r => !r.config.optional)
.map(r => `'${r.id}'`)
.join(', ');
const provided = [...(attachment.instance?.getDataRefs() ?? [])]
.map(r => `'${r.id}'`)
.join(', ');
throw new Error(
`input '${inputName}' did not receive required extension data '${ref.id}' from extension '${attachment.spec.id}'`,
`extension '${attachment.spec.id}' could not be attached because its output data (${provided}) does not match what the input '${inputName}' requires (${expected})`,
);
}
return value;