Skip to content

Commit 0d5c097

Browse files
committed
Clarify error message on undefined component instances, Closes #108
1 parent 179a6ad commit 0d5c097

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/preprocess/parameterproperty/ParameterPropertyHandlerRange.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ export class ParameterPropertyHandlerRange implements IParameterPropertyHandler
480480
const withTypes = value && value.properties.types.length > 0 ? ` with types "${value.properties.types.map(resource => resource.value)}"` : '';
481481
// eslint-disable-next-line @typescript-eslint/no-extra-parens
482482
const valueString = value ? (value.list ? `[${value.list.map(subValue => subValue.value).join(', ')}]` : value.value) : 'undefined';
483-
throw new ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"`, {
483+
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?` : '';
484+
throw new ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"${undefinedComponent}`, {
484485
cause: conflict,
485486
value: value || 'undefined',
486487
...Object.keys(genericsContext.bindings).length > 0 ?

test/unit/preprocess/parameterproperty/ParameterPropertyHandlerRange-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,7 @@ describe('ParameterPropertyHandlerRange', () => {
27902790
objectLoader.createCompactedResource('ex:param'),
27912791
genericsContext,
27922792
conflict,
2793-
)).toThrow('The value "ex:value" for parameter "ex:param" is not of required range type "any"');
2793+
)).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?`);
27942794
});
27952795

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

0 commit comments

Comments
 (0)