| OLD | NEW |
| (Empty) | |
| 1 /** |
| 2 * @license |
| 3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 4 * |
| 5 * This code may only be used under the BSD style license found at polymer.githu
b.io/LICENSE.txt |
| 6 * The complete set of authors may be found at polymer.github.io/AUTHORS.txt |
| 7 * The complete set of contributors may be found at polymer.github.io/CONTRIBUTO
RS.txt |
| 8 * Code distributed by Google as part of the polymer project is also subject to |
| 9 * an additional IP rights grant found at polymer.github.io/PATENTS.txt |
| 10 */ |
| 11 (function(scope) { |
| 12 'use strict'; |
| 13 |
| 14 var parse = scope.parse || require('./parsing').parse; |
| 15 var pretty = scope.pretty || require('./formatting').pretty; |
| 16 |
| 17 function normalize(error, prettyOptions) { |
| 18 if (error.parsedStack) return error; |
| 19 var message = error.message || error.description || error || '<unknown error>'
; |
| 20 var parsedStack = []; |
| 21 try { |
| 22 parsedStack = parse(error.stack || error.toString()); |
| 23 } catch (error) { |
| 24 // Ah well. |
| 25 } |
| 26 |
| 27 if (parsedStack.length === 0 && error.fileName) { |
| 28 parsedStack.push({ |
| 29 method: '', |
| 30 location: error.fileName, |
| 31 line: error.lineNumber, |
| 32 column: error.columnNumber, |
| 33 }); |
| 34 } |
| 35 |
| 36 if (!prettyOptions || !prettyOptions.showColumns) { |
| 37 for (var i = 0, line; line = parsedStack[i]; i++) { |
| 38 delete line.column; |
| 39 } |
| 40 } |
| 41 |
| 42 var prettyStack = message; |
| 43 if (parsedStack.length > 0) { |
| 44 prettyStack = prettyStack + '\n' + pretty(parsedStack, prettyOptions); |
| 45 } |
| 46 |
| 47 var cleanErr = Object.create(Error.prototype); |
| 48 cleanErr.message = message; |
| 49 cleanErr.stack = prettyStack; |
| 50 cleanErr.parsedStack = parsedStack; |
| 51 |
| 52 return cleanErr; |
| 53 } |
| 54 |
| 55 scope.normalize = normalize; |
| 56 })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky |
| {})); |
| 57 |
| OLD | NEW |