fix(gateway): remove cause from custom handling of GatewayAuthenticationError error#11111
fix(gateway): remove cause from custom handling of GatewayAuthenticationError error#11111
cause from custom handling of GatewayAuthenticationError error#11111Conversation
| export function wrapGatewayError(error: unknown): unknown { | ||
| if ( | ||
| GatewayAuthenticationError.isInstance(error) || | ||
| GatewayModelNotFoundError.isInstance(error) |
There was a problem hiding this comment.
@Lars @mclenhard throwing the custom unauthenticated error for GatewayModelNotFoundError was incorrect. Do we want a custom error for when a model was not found? I don't think we need it?
| export function wrapGatewayError(error: unknown): unknown { | ||
| if ( | ||
| GatewayAuthenticationError.isInstance(error) || | ||
| GatewayModelNotFoundError.isInstance(error) |
There was a problem hiding this comment.
The cause property was removed from the AISDKError constructor, breaking the error chain and losing important debugging information.
View Details
📝 Patch Details
diff --git a/packages/ai/src/prompt/wrap-gateway-error.ts b/packages/ai/src/prompt/wrap-gateway-error.ts
index 0417be108..4bb058e1e 100644
--- a/packages/ai/src/prompt/wrap-gateway-error.ts
+++ b/packages/ai/src/prompt/wrap-gateway-error.ts
@@ -7,6 +7,7 @@ export function wrapGatewayError(error: unknown): unknown {
name: 'GatewayError',
message:
'Unauthenticated. Configure AI_GATEWAY_API_KEY or configure and use a provider module. Learn more: https://vercel.link/unauthenticated-ai-gateway-v6',
+ cause: error,
});
}
Analysis
Missing cause property breaks error chain in wrapGatewayError()
What fails: wrapGatewayError() in packages/ai/src/prompt/wrap-gateway-error.ts does not pass the cause property when creating the wrapped AISDKError, breaking the error causality chain for debugging and error diagnostics.
How to reproduce:
import { wrapGatewayError } from './packages/ai/src/prompt/wrap-gateway-error';
import { GatewayAuthenticationError } from '@ai-sdk/gateway';
const originalError = new GatewayAuthenticationError({
message: 'Auth failed',
statusCode: 401,
cause: new Error('Network timeout')
});
const wrappedError = wrapGatewayError(originalError) as AISDKError;
console.log(wrappedError.cause); // undefined - original error is lostResult: The cause property is undefined on the wrapped error, losing reference to the original GatewayAuthenticationError and preventing access to underlying error context (e.g., network errors, status codes from the authentication attempt).
Expected: The cause property should contain the original GatewayAuthenticationError instance, preserving the error chain for proper error diagnostics and monitoring. The AISDKError class supports optional cause parameter as defined in packages/provider/src/errors/ai-sdk-error.ts. All existing tests pass when cause: error is included.
Reference: AISDKError constructor accepts cause as optional parameter for error chaining. Error causality chains are standard practice in error handling for debugging and production monitoring (Error Cause property - MDN Web Docs).
cause from custom handling of GatewayAuthenticationError errorcause from custom handling of GatewayAuthenticationError error
|
superseded by #11113 |
No description provided.