From b731a5a44cdd69be0524a3074c44d6f8fa33cea6 Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Thu, 7 May 2020 15:21:26 -0700 Subject: [PATCH] WIP: COMPONENT_NOT_FOUND should be INTERFACE_NOT_FOUND --- lib/container.js | 4 ++-- lib/errors/componentnotfound.js | 5 +++-- lib/resolvers/id.js | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/container.js b/lib/container.js index a95911b..96d9a93 100644 --- a/lib/container.js +++ b/lib/container.js @@ -185,7 +185,7 @@ Container.prototype.create = function(id, parent, ecomp, options) { // Reject with a more informative error message that indicates the // requiring component. This assists the developer in finding and // fixing the cause of error. - reject(new ComponentNotFoundError("Unable to create component '" + id + "' required by '" + (parent && parent.id || 'unknown') + "'")); + reject(new ComponentNotFoundError("Unable to create component '" + id + "' required by '" + (parent && parent.id || 'unknown') + "'", id)); } else if (err) { return reject(err); } @@ -253,7 +253,7 @@ Container.prototype._loadComponent = function(id, cb) { return cb(null, spec); } } - return cb(new ComponentNotFoundError("Cannot find component '" + id + "'")); + return cb(new ComponentNotFoundError("Cannot find component '" + id + "'", id)); } /** diff --git a/lib/errors/componentnotfound.js b/lib/errors/componentnotfound.js index 7a69a38..061ea2f 100644 --- a/lib/errors/componentnotfound.js +++ b/lib/errors/componentnotfound.js @@ -3,11 +3,12 @@ * * @api public */ -function ComponentNotFoundError(message) { +function ComponentNotFoundError(message, iface) { Error.call(this); Error.captureStackTrace(this, arguments.callee); this.message = message; - this.code = 'COMPONENT_NOT_FOUND'; + this.code = 'IMPLEMENTATION_NOT_FOUND'; + this.interface = iface; } /** diff --git a/lib/resolvers/id.js b/lib/resolvers/id.js index b355531..3741f8f 100644 --- a/lib/resolvers/id.js +++ b/lib/resolvers/id.js @@ -17,6 +17,8 @@ */ module.exports = function() { + // TODO: Redo this to search the container for object Ids, and don't impose a naming constraint + return function(id) { if (/^[\w\-\.\/]+$/.test(id)) { return id;