Skip to content
Browse files

improved handing of file errors in wsh.js

  • Loading branch information...
1 parent 90ef431 commit 84cba54e38b605b8f1b5994dbf926b2f34ef30a8 @benblank committed Apr 27, 2011
Showing with 29 additions and 3 deletions.
  1. +29 −3 env/wsh.js
View
32 env/wsh.js
@@ -2,6 +2,14 @@
/*global JSHINT: false */
(function() {
+ function readFile(path) {
+ try {
+ return new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(path, 1).ReadAll();
+ } catch (ex) {
+ return null;
+ }
+ }
+
var formatters = {
errors: function(errors, lines) {
for (var i = 0; i < errors.length; i++) {
@@ -62,7 +70,15 @@
scriptPath = scriptPath.substr(0, scriptPath.length - scriptName.length);
// load JSHint if the two scripts have not been concatenated
- if (typeof JSHINT === "undefined") eval(new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(scriptPath + "..\\jshint.js", 1).ReadAll());
+ if (typeof JSHINT === "undefined") {
+ eval(readFile(scriptPath + "..\\jshint.js"));
+
+ if (typeof JSHINT === "undefined") {
+ WScript.StdOut.WriteLine("ERROR: Could not find 'jshint.js'.");
+
+ WScript.Quit(-2);
+ }
+ }
var globals = {};
var options = {};
@@ -86,9 +102,19 @@
var script = unnamed(0);
if (script === "-") {
- script = WScript.StdIn.ReadAll();
+ try {
+ script = WScript.StdIn.ReadAll();
+ } catch (ex) {
+ script = null;
+ }
} else {
- script = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(script, 1).ReadAll();
+ script = readFile(script);
+ }
+
+ if (script === null) {
+ WScript.StdOut.WriteLine("ERROR: Could not read target script.");
+
+ WScript.Quit(2);
}
for (var etor = new Enumerator(named); !etor.atEnd(); etor.moveNext()) {

0 comments on commit 84cba54

Please sign in to comment.
Something went wrong with that request. Please try again.