Skip to content

Commit

Permalink
fix(frame): do not crash when filepath does not exist (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov authored and thetutlage committed Jul 10, 2018
1 parent 7fd55fc commit dac572d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Youch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Youch {
fs.readFile(frame.getFileName(), 'utf-8', (error, contents) => {
if (error) {
resolve(null)
return
}

const lines = contents.split(/\r?\n/)
Expand Down
20 changes: 20 additions & 0 deletions test/youch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ test.group('Youch', () => {
.catch(done)
})

// Source map package, webpack bundling, dynamic loading,
// there are many reasons why the filepath in the stack does not exist.
test('does not error on non-existing files', (assert, done) => {
const error = new Error('this is bar')
error.stack = error.stack.replace(__dirname, 'invalid-path')
const youch = new Youch(error, {})

youch
._parseError()
.then((stack) => {
const frame = stack.find(f => f.fileName.includes('invalid-path'))
return youch._getFrameSource(frame)
})
.then((source) => {
assert.deepEqual(source, null)
done()
})
.catch(done)
})

test('return active class when index is 0', (assert) => {
const error = new Error('this is bar')
const youch = new Youch(error, {})
Expand Down

1 comment on commit dac572d

@isuttell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! We've been running into this bug in our application. When is this going to be published?

Please sign in to comment.