Add friendlier errors when no adaptor/driver found
This commit is contained in:
parent
2acc07b443
commit
337074f34f
21
lib/robot.js
21
lib/robot.js
|
@ -293,7 +293,11 @@ namespace("Cylon", function() {
|
||||||
// Returns the registered module name
|
// Returns the registered module name
|
||||||
Robot.prototype.registerAdaptor = function(moduleName, adaptorName) {
|
Robot.prototype.registerAdaptor = function(moduleName, adaptorName) {
|
||||||
if (this.adaptors[adaptorName] == null) {
|
if (this.adaptors[adaptorName] == null) {
|
||||||
return this.adaptors[adaptorName] = require(moduleName);
|
try {
|
||||||
|
return this.adaptors[adaptorName] = require(moduleName);
|
||||||
|
} catch (e) {
|
||||||
|
this._missingModuleError(moduleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -347,7 +351,11 @@ namespace("Cylon", function() {
|
||||||
// Returns the registered module nam//
|
// Returns the registered module nam//
|
||||||
Robot.prototype.registerDriver = function(moduleName, driverName) {
|
Robot.prototype.registerDriver = function(moduleName, driverName) {
|
||||||
if (this.drivers[driverName] == null) {
|
if (this.drivers[driverName] == null) {
|
||||||
return this.drivers[driverName] = require(moduleName);
|
try {
|
||||||
|
return this.drivers[driverName] = require(moduleName);
|
||||||
|
} catch (e) {
|
||||||
|
this._missingModuleError(moduleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -358,6 +366,15 @@ namespace("Cylon", function() {
|
||||||
return "[Robot name='" + this.name + "']";
|
return "[Robot name='" + this.name + "']";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Robot.prototype._missingModuleError = function(module) {
|
||||||
|
var string = "Cannot find the '" + module + "' module. ";
|
||||||
|
string += "Please install it with 'npm install " + module + "' and try again.";
|
||||||
|
|
||||||
|
console.log(string);
|
||||||
|
|
||||||
|
process.emit('SIGINT');
|
||||||
|
};
|
||||||
|
|
||||||
return Robot;
|
return Robot;
|
||||||
|
|
||||||
})(EventEmitter);
|
})(EventEmitter);
|
||||||
|
|
Loading…
Reference in New Issue