diff --git a/lib/robot.js b/lib/robot.js index 326a137..33b7410 100644 --- a/lib/robot.js +++ b/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