Skip to content

Commit 579c044

Browse files
committed
fix(stdlib): make sure to flush Sentry before exit
1 parent 9746b01 commit 579c044

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/stdlib/src/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ export function mainFn(meta, cb) {
101101
process.on("unhandledRejection", (reason, promise) => {
102102
if (_compasSentryExport) {
103103
_compasSentryExport.captureException(reason);
104+
return _compasSentryExport.close(1000).then(() => {
105+
unhandled({
106+
type: "unhandledRejection",
107+
reason: AppError.format(reason),
108+
promise,
109+
});
110+
});
104111
}
105112

106113
unhandled({
@@ -113,6 +120,13 @@ export function mainFn(meta, cb) {
113120
process.on("uncaughtException", (error, origin) => {
114121
if (_compasSentryExport) {
115122
_compasSentryExport.captureException(error);
123+
return _compasSentryExport.close(1000).then(() => {
124+
unhandled({
125+
type: "uncaughtException",
126+
error: AppError.format(error),
127+
origin,
128+
});
129+
});
116130
}
117131

118132
unhandled({
@@ -132,6 +146,13 @@ export function mainFn(meta, cb) {
132146
Promise.resolve(cb(logger)).catch((e) => {
133147
if (_compasSentryExport) {
134148
_compasSentryExport.captureException(e);
149+
return _compasSentryExport.close(1000).then(() => {
150+
unhandled({
151+
type: "error",
152+
message: "Error caught from callback passed in `mainFn`",
153+
error: AppError.format(e),
154+
});
155+
});
135156
}
136157

137158
unhandled({

0 commit comments

Comments
 (0)