Skip to content

Commit 774b6fe

Browse files
committed
Merge pull request #41 from drauggres/master
formatting error created in wrapper and using its cached_trace
2 parents dd46b78 + 2c5099d commit 774b6fe

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

dist/longjohn.js

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/longjohn.coffee

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ prepareStackTrace = (error, structured_stack_trace) ->
7171
error.__previous__ = current_trace_error if !error.__previous__? and in_prepare is 1
7272

7373
if error.__previous__?
74-
previous_stack = error.__previous__.stack
74+
previous_stack = error.__previous__.__cached_trace__
7575
if previous_stack?.length > 0
7676
error.__cached_trace__.push(create_callsite(exports.empty_frame))
7777
error.__cached_trace__.push(previous_stack...)
@@ -90,7 +90,15 @@ limit_frames = (stack) ->
9090
while previous? and count > 1
9191
previous = previous.__previous__
9292
--count
93-
delete previous.__previous__ if previous?
93+
if previous?
94+
which_previous_must_delete = previous
95+
if previous?.__previous__?.__cached_trace__
96+
len = previous.__previous__.__cached_trace__.length
97+
previous = stack
98+
while previous? and previous != which_previous_must_delete.__previous__
99+
previous.__cached_trace__.length -= (len+1)
100+
previous = previous.__previous__
101+
delete previous.__previous__
94102

95103
ERROR_ID = 1
96104

@@ -111,6 +119,7 @@ wrap_callback = (callback, location) ->
111119
trace_error.__location__ = location
112120
trace_error.__previous__ = current_trace_error
113121
trace_error.__trace_count__ = if current_trace_error? then current_trace_error.__trace_count__ + 1 else 1
122+
trace_error.stack
114123

115124
limit_frames(trace_error)
116125

test/test-longjohn.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ describe 'longjohn', ->
99
fs = require('fs')
1010

1111
fs.readFile 'not_there.txt', 'utf8', (err, text) ->
12-
return done() if err? and err instanceof Error and err.stack is "Error: ENOENT, open 'not_there.txt'"
12+
return done() if err? and err instanceof Error and
13+
(err.stack is "Error: ENOENT, open 'not_there.txt'" or
14+
err.stack is "Error: ENOENT, open 'not_there.txt'\n at Error (native)")
1315
assert.fail()
1416

1517
it 'should track frames across setTimeout', (done) ->

0 commit comments

Comments
 (0)