Skip to content

Commit

Permalink
fix(): print better error when ref syntax is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jan 14, 2021
1 parent 91dd84b commit f070da4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/factories/definitions.factory.ts
Expand Up @@ -90,8 +90,18 @@ export class DefinitionsFactory {
return;
}
if (typeof optionsOrType?.ref === 'function') {
optionsOrType.ref =
(optionsOrType.ref as Function)()?.name ?? optionsOrType.ref;
try {
optionsOrType.ref =
(optionsOrType.ref as Function)()?.name ?? optionsOrType.ref;
} catch (err) {
if (err instanceof TypeError) {
const refClassName = (optionsOrType.ref as Function)?.name;
throw new Error(
`Unsupported syntax: Class constructor "${refClassName}" cannot be invoked without 'new'. Make sure to wrap your class reference in an arrow function (for example, "ref: () => ${refClassName}").`,
);
}
throw err;
}
} else if (Array.isArray(optionsOrType.type)) {
if (optionsOrType.type.length > 0) {
this.inspectRef(optionsOrType.type[0]);
Expand Down

0 comments on commit f070da4

Please sign in to comment.