| 1 |
|
| 2 |
const errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack']; |
| 3 |
|
| 4 |
function Exception(message, node) { |
| 5 |
let loc = node && node.loc, |
| 6 |
line, |
| 7 |
column; |
| 8 |
if (loc) { |
| 9 |
line = loc.start.line; |
| 10 |
column = loc.start.column; |
| 11 |
|
| 12 |
message += ' - ' + line + ':' + column; |
| 13 |
} |
| 14 |
|
| 15 |
let tmp = Error.prototype.constructor.call(this, message); |
| 16 |
|
| 17 |
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. |
| 18 |
for (let idx = 0; idx < errorProps.length; idx++) { |
| 19 |
this[errorProps[idx]] = tmp[errorProps[idx]]; |
| 20 |
} |
| 21 |
|
| 22 |
/* istanbul ignore else */ |
| 23 |
if (Error.captureStackTrace) { |
| 24 |
Error.captureStackTrace(this, Exception); |
| 25 |
} |
| 26 |
|
| 27 |
try { |
| 28 |
if (loc) { |
| 29 |
this.lineNumber = line; |
| 30 |
|
| 31 |
// Work around issue under safari where we can't directly set the column value |
| 32 |
/* istanbul ignore next */ |
| 33 |
if (Object.defineProperty) { |
| 34 |
Object.defineProperty(this, 'column', { |
| 35 |
value: column, |
| 36 |
enumerable: true |
| 37 |
}); |
| 38 |
} else { |
| 39 |
this.column = column; |
| 40 |
} |
| 41 |
} |
| 42 |
} catch (nop) { |
| 43 |
/* Ignore if the browser is very particular */ |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
Exception.prototype = new Error(); |
| 48 |
|
| 49 |
export default Exception; |
| 50 |
|