@@ -8,6 +8,7 @@ let ignoreStackLines = [];
88
99const avaInternals = / \/ a v a \/ (?: l i b \/ ) ? [ \w - ] + \. j s : \d + : \d + \) ? $ / ;
1010const avaDependencies = / \/ n o d e _ m o d u l e s \/ (?: b l u e b i r d | e m p o w e r - c o r e | (?: a v a \/ n o d e _ m o d u l e s \/ ) ? (?: b a b e l - r u n t i m e | c o r e - j s ) ) \/ / ;
11+ const stackFrameLine = / ^ .+ ( \( .+ : [ 0 - 9 ] + : [ 0 - 9 ] + \) | : [ 0 - 9 ] + : [ 0 - 9 ] + ) $ / ;
1112
1213if ( ! debug . enabled ) {
1314 ignoreStackLines = StackUtils . nodeInternals ( ) ;
@@ -17,21 +18,55 @@ if (!debug.enabled) {
1718
1819const stackUtils = new StackUtils ( { internals : ignoreStackLines } ) ;
1920
21+ function extractFrames ( stack ) {
22+ return stack
23+ . split ( '\n' )
24+ . map ( line => line . trim ( ) )
25+ . filter ( line => stackFrameLine . test ( line ) )
26+ . join ( '\n' ) ;
27+ }
28+
29+ /**
30+ * Given a string value of the format generated for the `stack` property of a
31+ * V8 error object, return a string that contains only stack frame information
32+ * for frames that have relevance to the consumer.
33+ *
34+ * For example, given the following string value:
35+ *
36+ * ```
37+ * Error
38+ * at inner (/home/ava/ex.js:7:12)
39+ * at /home/ava/ex.js:12:5
40+ * at outer (/home/ava/ex.js:13:4)
41+ * at Object.<anonymous> (/home/ava/ex.js:14:3)
42+ * at Module._compile (module.js:570:32)
43+ * at Object.Module._extensions..js (module.js:579:10)
44+ * at Module.load (module.js:487:32)
45+ * at tryModuleLoad (module.js:446:12)
46+ * at Function.Module._load (module.js:438:3)
47+ * at Module.runMain (module.js:604:10)
48+ * ```
49+ *
50+ * ...this function returns the following string value:
51+ *
52+ * ```
53+ * inner (/home/ava/ex.js:7:12)
54+ * /home/ava/ex.js:12:5
55+ * outer (/home/ava/ex.js:13:4)
56+ * Object.<anonymous> (/home/ava/ex.js:14:3)
57+ * ```
58+ */
2059module . exports = stack => {
2160 if ( ! stack ) {
2261 return '' ;
2362 }
2463
64+ stack = extractFrames ( stack ) ;
2565 // Workaround for https://github.com/tapjs/stack-utils/issues/14
2666 // TODO: fix it in `stack-utils`
2767 stack = cleanStack ( stack ) ;
2868
29- const title = stack . split ( '\n' ) [ 0 ] ;
30- const lines = stackUtils
31- . clean ( stack )
32- . split ( '\n' )
33- . map ( x => ` ${ x } ` )
34- . join ( '\n' ) ;
35-
36- return `${ title } \n${ lines } ` ;
69+ return stackUtils . clean ( stack )
70+ // Remove the trailing newline inserted by the `stack-utils` module
71+ . trim ( ) ;
3772} ;
0 commit comments