Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/errors/componentcreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
* @api public
*/
function ComponentCreateError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_CREATE_ERROR';
// from https://stackoverflow.com/a/17936621/824979
const temp = Error.apply(this, arguments);
temp.name = this.name = 'ComponentCreateError';
temp.code = this.code = 'COMPONENT_CREATE_ERROR';
this.message = temp.message;
Object.defineProperty(this, 'stack', {
get: function() {
return temp.stack
},
configurable: true
})
}

/**
* Inherit from `Error`.
*/
ComponentCreateError.prototype.__proto__ = Error.prototype;

const IntermediateInheritor = function () {};
IntermediateInheritor.prototype = Error.prototype;
ComponentCreateError.prototype = new IntermediateInheritor();

/**
* Expose `ComponentCreateError`.
Expand Down
19 changes: 14 additions & 5 deletions lib/errors/componentnotfound.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
* @api public
*/
function ComponentNotFoundError(message) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'COMPONENT_NOT_FOUND';
// from https://stackoverflow.com/a/17936621/824979
const temp = Error.apply(this, arguments);
temp.name = this.name = 'ComponentNotFoundError';
temp.code = this.code = 'COMPONENT_NOT_FOUND';
this.message = temp.message;
Object.defineProperty(this, 'stack', {
get: function() {
return temp.stack
},
configurable: true
})
}

/**
* Inherit from `Error`.
*/
ComponentNotFoundError.prototype.__proto__ = Error.prototype;

const IntermediateInheritor = function () {};
IntermediateInheritor.prototype = Error.prototype
ComponentNotFoundError.prototype = new IntermediateInheritor()

/**
* Expose `ComponentNotFoundError`.
Expand Down
19 changes: 14 additions & 5 deletions lib/errors/interfacenotfound.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
* @api public
*/
function InterfaceNotFoundError(message, iface) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = message;
this.code = 'INTERFACE_NOT_FOUND';
// from https://stackoverflow.com/a/17936621/824979
const temp = Error.apply(this, arguments);
temp.name = this.name = 'InterfaceNotFoundError';
temp.code = this.code = 'INTERFACE_NOT_FOUND';
this.message = temp.message;
Object.defineProperty(this, 'stack', {
get: function() {
return temp.stack
},
configurable: true
})
this.interface = iface;
}

/**
* Inherit from `Error`.
*/
InterfaceNotFoundError.prototype.__proto__ = Error.prototype;
const IntermediateInheritor = function () {};
IntermediateInheritor.prototype = Error.prototype;
InterfaceNotFoundError.prototype = new IntermediateInheritor();


/**
Expand Down
68 changes: 67 additions & 1 deletion test/container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('Container', function() {
it('should fail with error', function() {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("Unable to create component 'unknown' required by 'unknown'");
expect(error.code).to.equal("COMPONENT_NOT_FOUND");
expect(error.stack.split("\n")[0]).to.equal("ComponentNotFoundError: Unable to create component 'unknown' required by 'unknown'")
});
});

Expand Down Expand Up @@ -71,7 +73,71 @@ describe('Container', function() {
});

});

describe('unknown interface', function() {

describe('created without a parent', function() {
var error;

before(function(done) {
container.create('$unknown')
.then(function(obj) {
done(new Error('should not create object'));
})
.catch(function(err) {
error = err;
done();
});
})

it('should fail with error', function() {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("Cannot find component implementing interface '$unknown' required by 'unknown'");
expect(error.code).to.equal("INTERFACE_NOT_FOUND");
expect(error.stack.split("\n")[0]).to.equal("InterfaceNotFoundError: Cannot find component implementing interface '$unknown' required by 'unknown'")
});
});

describe('created with a parent', function() {
var error;

before(function(done) {
container.create('$unknown', { id: 'main' })
.then(function(obj) {
done(new Error('should not create object'));
})
.catch(function(err) {
error = err;
done();
});
})

it('should fail with error', function() {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("Cannot find component implementing interface '$unknown' required by 'main'");
});
});

describe('created with a parent, lacking an id', function() {
var error;

before(function(done) {
container.create('$unknown', {})
.then(function(obj) {
done(new Error('should not create object'));
})
.catch(function(err) {
error = err;
done();
});
})

it('should fail with error', function() {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal("Cannot find component implementing interface '$unknown' required by 'unknown'");
});
});

});
describe.skip('async component', function() {
var container = new Container();
container.use(require('./fixtures/sources/async'));
Expand Down