added notice for lack of ability to get backtraces from within modules
Showing
1 changed file
with
18 additions
and
3 deletions
... | @@ -206,7 +206,13 @@ phantom.loadCasper = function loadCasper() { | ... | @@ -206,7 +206,13 @@ phantom.loadCasper = function loadCasper() { |
206 | } | 206 | } |
207 | var scriptCode = phantom.getScriptCode(file); | 207 | var scriptCode = phantom.getScriptCode(file); |
208 | var fn = new Function('require', 'module', 'exports', scriptCode); | 208 | var fn = new Function('require', 'module', 'exports', scriptCode); |
209 | fn(_require, module, module.exports); | 209 | try { |
210 | fn(_require, module, module.exports); | ||
211 | } catch (e) { | ||
212 | var error = new CasperError('__mod_error(' + path + '):: ' + e); | ||
213 | error.file = file; | ||
214 | throw error; | ||
215 | } | ||
210 | requireCache[file] = module; | 216 | requireCache[file] = module; |
211 | return module.exports; | 217 | return module.exports; |
212 | }; | 218 | }; |
... | @@ -227,9 +233,18 @@ phantom.loadCasper = function loadCasper() { | ... | @@ -227,9 +233,18 @@ phantom.loadCasper = function loadCasper() { |
227 | */ | 233 | */ |
228 | phantom.onError = function phantom_onError(msg, backtrace) { | 234 | phantom.onError = function phantom_onError(msg, backtrace) { |
229 | var c = require('colorizer').create(); | 235 | var c = require('colorizer').create(); |
230 | if (msg) { | 236 | var match = /^(.*): __mod_error(.*):: (.*)/.exec(msg); |
231 | console.error(c.colorize(msg, 'RED_BAR', 80)); | 237 | var notices = []; |
238 | if (match && match.length === 4) { | ||
239 | notices.push(' in module ' + match[2]); | ||
240 | notices.push(' NOTICE: errors within modules cannot be backtraced yet.'); | ||
241 | cls = match[1]; | ||
242 | msg = match[3]; | ||
232 | } | 243 | } |
244 | console.error(c.colorize(msg, 'RED_BAR', 80)); | ||
245 | notices.forEach(function(notice) { | ||
246 | console.error(c.colorize(notice, 'COMMENT')); | ||
247 | }); | ||
233 | backtrace.forEach(function(item) { | 248 | backtrace.forEach(function(item) { |
234 | var message = require('fs').absolute(item.file) + ":" + c.colorize(item.line, "COMMENT"); | 249 | var message = require('fs').absolute(item.file) + ":" + c.colorize(item.line, "COMMENT"); |
235 | if (item['function']) { | 250 | if (item['function']) { | ... | ... |
-
Please register or sign in to post a comment