fix(server): stop logging whole error objects on the internal API endpoint - #2375
Conversation
…point Log only the error message at the four console sites in the internal API endpoint instead of dumping the full Error object. The 503 response already carries the last error message, so the extra detail in the log was just noise.
felladrin
left a comment
There was a problem hiding this comment.
Fix is correct and converges on the existing sibling-hook convention: all four console sites in internalApiEndpointServerHook.ts now log error.message (falling back to the raw value for non-Error throws), so the APICallError's requestBodyValues - the system prompt plus the query - no longer reaches the log. error.message on an AI SDK APICallError is built from the response error body, never from requestBodyValues, so the message-only form carries no prompt text. The retry loop is untouched and the 503/SSE paths already used .message, so nothing downstream changes. Tests pass locally (37/37) and CI is green.
Non-blocking follow-up: the new tests guard by type (no Error instance logged at arg index 1) rather than by leak (prompt text absent). That has two blind spots - a future console.error("...", error.message, error.requestBodyValues) or a { ...error } spread would pass, and the console.warn site at line 339 is untested. A leak-shaped test (drive the endpoint with an error carrying a distinctive requestBodyValues prompt, inspect() all console args, assert the prompt is absent) closes both and matches the issue's acceptance criteria. Worth adding in a follow-up.
Closes #2358.
The internal API endpoint was dumping full
Errorobjects into the server log in four places. In practice that means stack traces plus whatever internal state rode along on the error, which is noisy and gets in the way when you're trying to scan the log for what actually happened.The two spots called out in the issue (
Error during streaming:andError in internal API endpoint:) plus the two neighboring ones with the same pattern (Error fetching models:and the model-refetch warning) now log just the error message. The 503 response already carries the last error message, so callers don't lose anything - this only makes the log line readable.Changes
error.message(falling back to the raw value for non-Errorthrows) at all four console sites inserver/internalApiEndpointServerHook.ts.Tests
console.errorand assert only the message is logged, not theErrorinstance. The stream-failure one fails against the previous code.npx vitest run server/internalApiEndpointServerHook.test.ts- 37 passednpx biome checkon the two changed files - cleannpx tsc --noEmit- clean