Skip to content

Commit a891603

Browse files
committed
Fix wrong api usage errors being swallowed
1 parent 869ab9b commit a891603

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/connection.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function Connection(options = {}) {
6666
? socket.write(frontend.Close())
6767
: socket.write(frontend.Execute(backend.query.cursor.rows))
6868
}).catch(err => {
69-
socket.write(frontend.Close())
7069
backend.query.reject(err)
70+
socket.write(frontend.Close())
7171
})
7272
}
7373

@@ -114,6 +114,7 @@ function Connection(options = {}) {
114114
}
115115

116116
function send(query, { sig, str, args = [] }) {
117+
try {
117118
query.str = str
118119
query.args = args
119120
query.result = []
@@ -134,6 +135,9 @@ function Connection(options = {}) {
134135
open
135136
? socket.write(buffer)
136137
: (messages.push(buffer), connect())
138+
} catch (err) {
139+
query.reject(err)
140+
}
137141
}
138142

139143
function connect() {

tests/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1084,3 +1084,8 @@ o('Catches connection config errors', async() => {
10841084
await sql`select 1`.catch((e) => e.message)
10851085
]
10861086
})
1087+
1088+
o('Catches query format errors', async() => [
1089+
'wat',
1090+
await sql.unsafe({ toString: () => { throw new Error('wat') } }).catch((e) => e.message)
1091+
])

0 commit comments

Comments
 (0)