Skip to content

Commit

Permalink
Merge pull request #7 from npm/jpg619/fix-non-bb-catch-style
Browse files Browse the repository at this point in the history
Replace non Bluebird catch styles
  • Loading branch information
jpg619 authored Jun 3, 2024
2 parents 2f83639 + a836210 commit dfaf43a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
coverage/
node_modules
package-lock.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@npm/pg-db-session",
"version": "1.3.2",
"version": "1.4.0",
"description": "domain-attached database sessions",
"main": "db-session.js",
"scripts": {
Expand Down
32 changes: 24 additions & 8 deletions test/basic-api-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ test('test transaction outside of session', assert => {

testTransaction()
.then(() => { throw new Error('expected error') })
.catch(db.NoSessionAvailable, () => assert.end())
.catch(err => assert.end(err))
.catch(err => {
if(err instanceof db.NoSessionAvailable) {
assert.end()
}
assert.end(err)
})
})

test('test atomic outside of session', assert => {
Expand All @@ -21,8 +25,12 @@ test('test atomic outside of session', assert => {

testAtomic()
.then(() => { throw new Error('expected error') })
.catch(db.NoSessionAvailable, () => assert.end())
.catch(err => assert.end(err))
.catch(err => {
if(err instanceof db.NoSessionAvailable) {
assert.end()
}
assert.end(err)
})
})

test('test getConnection after release', assert => {
Expand All @@ -36,8 +44,12 @@ test('test getConnection after release', assert => {
setImmediate(() => {
session.getConnection()
.then(pair => { throw new Error('should not reach here') })
.catch(db.NoSessionAvailable, () => assert.ok(1, 'caught err'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof db.NoSessionAvailable) {
assert.ok(1, 'caught err')
}
assert.fail(err)
})
.finally(assert.end)
})
})()
Expand Down Expand Up @@ -67,8 +79,12 @@ test('test transaction after release', assert => {
setImmediate(() => {
session.transaction(() => {})
.then(pair => { throw new Error('should not reach here') })
.catch(db.NoSessionAvailable, () => assert.ok(1, 'caught err'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof db.NoSessionAvailable) {
assert.ok(1, 'caught err')
}
assert.fail(err)
})
.finally(assert.end)
})
})()
Expand Down
16 changes: 12 additions & 4 deletions test/basic-atomic-error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ test('test error in BEGIN', assert => {
assert.fail('should not reach here.')
})()
})
.catch(BeginError, () => assert.ok(1, 'caught expected err'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof BeginError) {
assert.ok(1, 'caught expected err')
}
assert.fail(err)
})
.finally(() => domain1.exit())
.finally(assert.end)

Expand Down Expand Up @@ -100,8 +104,12 @@ test('test error in COMMIT', assert => {
return db.getConnection().then(pair => pair.release())
})()
})
.catch(CommitError, () => assert.ok(1, 'caught expected error'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof CommitError) {
assert.ok(1, 'caught expected error')
}
assert.fail(err)
})
.finally(() => domain1.exit())
.finally(assert.end)

Expand Down
14 changes: 10 additions & 4 deletions test/basic-session-error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ test('cannot connect', assert => {
})
}).then(() => {
throw new Error('expected an exception')
}).catch(TestError, () => assert.ok(1, 'saw exception')).then(() => {
domain1.exit()
}).catch(err => {
if(err instanceof TestError) {
assert.ok(1, 'saw exception')
} else {
throw err
}
}).then(() => {
domain1.exit()
}).then(() => assert.end())
.catch(assert.end)
})
.catch(assert.end)
})

// what happens when there's an error querying?
test('query error', assert => {
Expand Down
16 changes: 12 additions & 4 deletions test/basic-transaction-error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ test('test error in BEGIN', assert => {
assert.fail('should not reach here.')
})()
})
.catch(BeginError, () => assert.ok(1, 'caught expected err'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof BeginError) {
assert.ok(1, 'caught expected err')
}
assert.fail(err)
})
.finally(() => domain1.exit())
.finally(assert.end)

Expand Down Expand Up @@ -100,8 +104,12 @@ test('test error in COMMIT', assert => {
return db.getConnection().then(pair => pair.release())
})()
})
.catch(CommitError, () => assert.ok(1, 'caught expected error'))
.catch(err => assert.fail(err))
.catch(err => {
if(err instanceof CommitError) {
assert.ok(1, 'caught expected error')
}
assert.fail(err)
})
.finally(() => domain1.exit())
.finally(assert.end)

Expand Down

0 comments on commit dfaf43a

Please sign in to comment.