Skip to content

Commit

Permalink
Clarify error message on undefined component instances, Closes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Mar 4, 2024
1 parent 179a6ad commit 0d5c097
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ export class ParameterPropertyHandlerRange implements IParameterPropertyHandler
const withTypes = value && value.properties.types.length > 0 ? ` with types "${value.properties.types.map(resource => resource.value)}"` : '';
// eslint-disable-next-line @typescript-eslint/no-extra-parens
const valueString = value ? (value.list ? `[${value.list.map(subValue => subValue.value).join(', ')}]` : value.value) : 'undefined';
throw new ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"`, {
const undefinedComponent = value && value.term.termType === 'NamedNode' && value.properties.types.length === 0 ? `. "${valueString}" seems to refer to a component instance that is not defined yet. Did you forget an import?` : '';
throw new ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"${undefinedComponent}`, {
cause: conflict,
value: value || 'undefined',
...Object.keys(genericsContext.bindings).length > 0 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2790,7 +2790,7 @@ describe('ParameterPropertyHandlerRange', () => {
objectLoader.createCompactedResource('ex:param'),
genericsContext,
conflict,
)).toThrow('The value "ex:value" for parameter "ex:param" is not of required range type "any"');
)).toThrow(`The value "ex:value" for parameter "ex:param" is not of required range type "any". "ex:value" seems to refer to a component instance that is not defined yet. Did you forget an import?`);
});

it('handles a defined value with types', () => {
Expand Down

0 comments on commit 0d5c097

Please sign in to comment.