Skip to content

Commit

Permalink
fix: Return patched promise instead of original
Browse files Browse the repository at this point in the history
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes #1319.
  • Loading branch information
punya committed Aug 29, 2022
1 parent ed422ed commit 7a3ec29
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/plugins/plugin-pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PostgresPatchUtility {
promise: Promise<pg_7.QueryResult>,
span: Span
): Promise<pg_7.QueryResult> {
return (promise = promise.then(
return promise.then(
res => {
this.maybePopulateLabelsFromOutputs(span, null, res);
span.endSpan();
Expand All @@ -170,7 +170,7 @@ class PostgresPatchUtility {
span.endSpan();
throw err;
}
));
);
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ const plugin: Plugin = [
// Unlike in pg 6, the returned value can't be both a Promise and
// a Submittable. So we don't run the risk of double-patching
// here.
pgPatch.patchPromise(pgQuery, span);
pgQuery = pgPatch.patchPromise(pgQuery, span);
}
}
return pgQuery;
Expand Down

0 comments on commit 7a3ec29

Please sign in to comment.