Skip to content

Commit

Permalink
docs: fixed example for StackTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Sep 13, 2019
1 parent c3c167b commit d096a05
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,45 @@ yarn add prepare-stack-trace
### Node

```js
const StackFrame = require('stackframe');
const ErrorStackParser = require('error-stack-parser');
const prepareStackTrace = require('prepare-stack-trace');

//
// The following override is required until this PR is merged
// <https://github.com/stacktracejs/stackframe/pull/23>
//
StackFrame.prototype.toString = function() {
const fileName = this.getFileName() || '';
const lineNumber = this.getLineNumber() || '';
const columnNumber = this.getColumnNumber() || '';
const functionName = this.getFunctionName() || '';
if (this.getIsEval()) {
if (fileName) {
return (
'[eval] (' + fileName + ':' + lineNumber + ':' + columnNumber + ')'
);
}

return '[eval]:' + lineNumber + ':' + columnNumber;
}

if (functionName) {
return (
functionName +
' (' +
fileName +
':' +
lineNumber +
':' +
columnNumber +
')'
);
}

return fileName + ':' + lineNumber + ':' + columnNumber;
};

const err1 = new Error('Oops!');
const err2 = new Error('Error 1 will inherit this stack trace');
err1.stack = prepareStackTrace(err1, ErrorStackParser.parse(err2));
Expand Down

0 comments on commit d096a05

Please sign in to comment.