Merge pull request #283 from hybridgroup/add/syntax-checks
Add basic DSL error checks
This commit is contained in:
commit
2de8f9a44d
31
lib/robot.js
31
lib/robot.js
|
@ -46,6 +46,9 @@ var Robot = module.exports = function Robot(opts) {
|
|||
}, this);
|
||||
|
||||
this.initRobot(opts);
|
||||
|
||||
this.checkForBadSyntax(opts);
|
||||
|
||||
this.initConnections(opts);
|
||||
this.initDevices(opts);
|
||||
|
||||
|
@ -153,6 +156,34 @@ Robot.prototype.initRobot = function(opts) {
|
|||
}
|
||||
};
|
||||
|
||||
// Public: Checks options for bad Cylon syntax
|
||||
//
|
||||
// Returns nothing
|
||||
Robot.prototype.checkForBadSyntax = function(opts) {
|
||||
var self = this;
|
||||
|
||||
var RobotDSLError = new Error("Unable to start robot due to a syntax error");
|
||||
RobotDSLError.name = "RobotDSLError";
|
||||
|
||||
function has(prop) { return opts[prop] != null; }
|
||||
|
||||
function checkForSingleObjectSyntax(type) {
|
||||
var plural = type + "s";
|
||||
|
||||
if (has(type) && !has(plural)) {
|
||||
[
|
||||
"The single-object '" + type + "' syntax for robots is not valid.",
|
||||
"Instead, use the multiple-value '" + plural + "' key syntax.",
|
||||
"Details: http://cylonjs.com/documentation/guides/working-with-robots/"
|
||||
].forEach(function(str) { self.log("fatal", str); });
|
||||
|
||||
throw RobotDSLError;
|
||||
}
|
||||
}
|
||||
|
||||
["connection", "device"].forEach(checkForSingleObjectSyntax);
|
||||
};
|
||||
|
||||
// Public: Initializes all connections for the robot
|
||||
//
|
||||
// opts - options array passed to constructor
|
||||
|
|
Loading…
Reference in New Issue