typedi
Version:
Dependency injection for TypeScript.
34 lines • 1.64 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CannotInstantiateValueError = void 0;
const token_class_1 = require("../token.class");
/**
* Thrown when DI cannot inject value into property decorated by @Inject decorator.
*/
class CannotInstantiateValueError extends Error {
constructor(identifier) {
var _a, _b;
super();
this.name = 'CannotInstantiateValueError';
/** Normalized identifier name used in the error message. */
this.normalizedIdentifier = '<UNKNOWN_IDENTIFIER>';
// TODO: Extract this to a helper function and share between this and NotFoundError.
if (typeof identifier === 'string') {
this.normalizedIdentifier = identifier;
}
else if (identifier instanceof token_class_1.Token) {
this.normalizedIdentifier = `Token<${identifier.name || 'UNSET_NAME'}>`;
}
else if (identifier && (identifier.name || ((_a = identifier.prototype) === null || _a === void 0 ? void 0 : _a.name))) {
this.normalizedIdentifier =
`MaybeConstructable<${identifier.name}>` ||
`MaybeConstructable<${(_b = identifier.prototype) === null || _b === void 0 ? void 0 : _b.name}>`;
}
}
get message() {
return (`Cannot instantiate the requested value for the "${this.normalizedIdentifier}" identifier. ` +
`The related metadata doesn't contain a factory or a type to instantiate.`);
}
}
exports.CannotInstantiateValueError = CannotInstantiateValueError;
//# sourceMappingURL=cannot-instantiate-value.error.js.map
;