Commit 0640e295 0640e295951d12666f9e2b2b25981dbb8cb10c6a by Nicolas Perriault

fixes #343 - better script checks

1 parent 24942703
...@@ -39,7 +39,15 @@ if (phantom.version.major === 1 && phantom.version.minor < 7) { ...@@ -39,7 +39,15 @@ if (phantom.version.major === 1 && phantom.version.minor < 7) {
39 console.error('CasperJS needs at least PhantomJS v1.7 or later.'); 39 console.error('CasperJS needs at least PhantomJS v1.7 or later.');
40 phantom.exit(1); 40 phantom.exit(1);
41 } else { 41 } else {
42 try {
42 bootstrap(window); 43 bootstrap(window);
44 } catch (e) {
45 console.error(e);
46 (e.stackArray || []).forEach(function(entry) {
47 console.error(' In ' + entry.sourceURL + ':' + entry.line);
48 });
49 phantom.exit(1);
50 }
43 } 51 }
44 52
45 // Polyfills 53 // Polyfills
...@@ -136,7 +144,11 @@ function patchRequire(require, requireDirs) { ...@@ -136,7 +144,11 @@ function patchRequire(require, requireDirs) {
136 var scriptCode = fs.read(file); 144 var scriptCode = fs.read(file);
137 if (/\.coffee$/i.test(file)) { 145 if (/\.coffee$/i.test(file)) {
138 /*global CoffeeScript*/ 146 /*global CoffeeScript*/
147 try {
139 scriptCode = CoffeeScript.compile(scriptCode); 148 scriptCode = CoffeeScript.compile(scriptCode);
149 } catch (e) {
150 throw new Error('Unable to compile coffeescript:' + e);
151 }
140 } 152 }
141 return scriptCode; 153 return scriptCode;
142 })(file); 154 })(file);
...@@ -328,7 +340,15 @@ function bootstrap(global) { ...@@ -328,7 +340,15 @@ function bootstrap(global) {
328 phantom.casperArgs.drop(phantom.casperScript); 340 phantom.casperArgs.drop(phantom.casperScript);
329 341
330 // passed casperjs script execution 342 // passed casperjs script execution
331 phantom.injectJs(phantom.casperScript); 343 var injected = false;
344 try {
345 injected = phantom.injectJs(phantom.casperScript);
346 } catch (e) {
347 throw new global.CasperError('Error loading script ' + phantom.casperScript + ': ' + e);
348 }
349 if (!injected) {
350 throw new global.CasperError('Unable to load script ' + phantom.casperScript + '; check file syntax');
351 }
332 }; 352 };
333 353
334 if (!phantom.casperLoaded) { 354 if (!phantom.casperLoaded) {
......