Skip to content

The AI SDK requires more comprehensive error messages #711

@eightHundreds

Description

@eightHundreds

span.setError({
message: 'Error streaming response',
data: {
error:
request.tracing === true
? String(error)
: error instanceof Error
? error.name
: undefined,

For example, when the LLM provider returns an error, the span here hardcodes the error message as "Error streaming response" and sets data.error to error.name (in this case, it's AI_APICallError). However, this information is insufficient for troubleshooting and may even obscure the issue. Additionally, the error contains fields like responseBody that could aid in debugging.

I hope span.setError can record the original error object, so that I can assemble the information I need in TracingProcessor.onSpanEnd. If you're concerned about directly passing a JS object affecting the toJSON method, you could...

catch (error) {
  const errorData = {
    error: request.tracing === true
      ? String(error)
      : error instanceof Error
        ? error.name
        : undefined
  }
  Object.defineProperty(errorData, 'originalError', {
    value: error,
    enumerable: false, //  JSON.stringify will ignore originalError
    writable: true,
    configurable: true
  })
  // or
  errorData[Symbol.for('originalError')] = error;

  span.setError({
    message: 'Error streaming response',
    data: errorData
  });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions