-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled AbortError
causes Unhandled Rejection
#303
Comments
Facing the same issue. |
@arnab710 In fact, I mentioned the solution above—using Specifically, the code would look something like this: process.on("unhandledRejection", (err) => {
if (err instanceof DOMException && err.name === "AbortError") {
console.log(`[Abort] ${err.message}`);
return;
}
console.error(`[Unhandled rejection]`);
console.error(err);
}); This is one way to address it. However, it’s obvious that you won’t be able to identify where this error originated. You can’t tell whether it’s an error from your system or from Of course, you can also choose to use a package patch and fix the
function pump(): Promise<(() => Promise<void>) | undefined> {
return reader.read().then(({ value, done }) => {
// ...
}).catch(err => {
// ... catch Abort Error here
});
} |
This is affecting me now, handling this at the global process level is not ideal. Would like to see some proper handling here at the SDK-level. |
I don't really know how this error is occuring, but it often happens with Gemini completions in Russian language. If that internally is not related to the SDK itself, perhaps some of the SDK developers could report that to Google? |
I updated the package for the fix, but catching the error is still necessary at the global level, though I am also able to catch it from the stream now. |
@danny-avila interesting, would you mind sharing the stack trace? maybe we need to catch the abort error beyond the stream reader. |
Description of the bug:
When an
AbortController
is triggered (e.g., via timeout or manual abort), the SDK throws anAbortError
that cannot be caught usingtry...catch
. This results in anUnhandled Rejection
, forcing developers to handle it globally withprocess.on('unhandledRejection', ...)
.Here is the error log:
Suspected problematic code:
generative-ai-js/src/requests/stream-reader.ts
Lines 78 to 128 in 2df2af0
Actual vs expected behavior:
Actual:
AbortError
is not catchable bytry...catch
, causing unhandled promise rejections.Expected:
AbortError
should be catchable withintry...catch
in user code, without requiring global error handlers.Any other information you'd like to share?
none
The text was updated successfully, but these errors were encountered: