@@ -35,6 +35,8 @@ Object.assign(Postgres, {
35
35
toKebab
36
36
} )
37
37
38
+ const originCache = new Map ( )
39
+
38
40
module . exports = Postgres
39
41
40
42
function Postgres ( a , b ) {
@@ -159,7 +161,7 @@ function Postgres(a, b) {
159
161
}
160
162
161
163
function query ( query , connection , xs , args ) {
162
- query . origin = new Error ( 'Query failed' )
164
+ query . origin = options . debug ? new Error ( ) . stack : cachedError ( xs )
163
165
if ( ! query . raw && ( ! Array . isArray ( xs ) || ! Array . isArray ( xs . raw ) ) )
164
166
return nested ( xs , args )
165
167
@@ -178,6 +180,17 @@ function Postgres(a, b) {
178
180
return promise
179
181
}
180
182
183
+ function cachedError ( xs ) {
184
+ if ( originCache . has ( xs ) )
185
+ return originCache . get ( xs )
186
+
187
+ const x = Error . stackTraceLimit
188
+ Error . stackTraceLimit = 4
189
+ originCache . set ( xs , new Error ( ) . stack )
190
+ Error . stackTraceLimit = x
191
+ return originCache . get ( xs )
192
+ }
193
+
181
194
function nested ( first , rest ) {
182
195
const o = Object . create ( notPromise )
183
196
o . first = first
0 commit comments