Skip to content
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

Add a new VertexAI error type #8240

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented May 9, 2024

  • Added VertexAIError so that users can instanceof the errors from the VertexAI SDK.
  • Added optional HTTP fields to errors (status, statusText, errorDetails) (mirroring google-gemini/generative-ai-js@111e970)
  • Moved away from using ErrorFactory towards our new error type
  • Added a generic error code VertexAIErrorCode.ERROR to align with the generic error in the Google AI SDK GoogleGenerativeAIError

Testing

I tested this in a React application in Chrome and Safari, and in a Node project.
instanceof and the stack trace works in these environments.

Error output in different environments

Safari

image

Chrome

image

Node

VertexAIError [FirebaseError]: Error fetching from https://firebaseml.googleapis.com/v2beta/projects/<omitted>/locations/us-central1/publishers/google/models/gemini-1.5-pro-preview-0409:generateContent: [400 Bad Request] Invalid value at 'contents[0].parts[0].text' (TYPE_STRING), 1 [{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"contents[0].parts[0].text","description":"Invalid value at 'contents[0].parts[0].text' (TYPE_STRING), 1"}]}]
    at makeRequest (/Users/dlarocque/workspace/firebase/firebase-js-sdk/packages/vertexai/dist/index.cjs.js:408:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async generateContent (/Users/dlarocque/workspace/firebase/firebase-js-sdk/packages/vertexai/dist/index.cjs.js:747:22)
    at async run (/Users/dlarocque/workspace/test/vertex-gcs-filedata/index.js:19:20) {
  code: 'fetch-error',
  customData: undefined,
  status: 400,
  statusText: 'Bad Request',
  errorDetails: [
    {
      '@type': 'type.googleapis.com/google.rpc.BadRequest',
      fieldViolations: [
        {
          field: 'contents[0].parts[0].text',
          description: "Invalid value at 'contents[0].parts[0].text' (TYPE_STRING), 1"
        }
      ]
    }
  ],
  toString: [Function (anonymous)]
}

@dlarocque dlarocque requested a review from hsubox76 May 9, 2024 20:20
@dlarocque dlarocque requested a review from a team as a code owner May 9, 2024 20:20
Copy link

changeset-bot bot commented May 9, 2024

🦋 Changeset detected

Latest commit: d71e71d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/vertexai-preview Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dlarocque dlarocque requested review from a team as code owners May 9, 2024 20:22
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 9, 2024

Size Report 1

Affected Products

  • @firebase/vertexai-preview

    TypeBase (aa060a7)Merge (c869eaf)Diff
    browser25.2 kB25.5 kB+338 B (+1.3%)
    main25.8 kB26.1 kB+359 B (+1.4%)
    module25.2 kB25.5 kB+338 B (+1.3%)
  • firebase

    TypeBase (aa060a7)Merge (c869eaf)Diff
    firebase-vertexai-preview.js19.3 kB19.7 kB+395 B (+2.1%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/6JSfmZ0F88.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 9, 2024

Size Analysis Report 1

Affected Products

  • @firebase/vertexai-preview

    • BlockReason

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.94 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • ChatSession

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size14.4 kB14.2 kB-222 B (-1.5%)
      size-with-ext-deps32.8 kB32.6 kB-218 B (-0.7%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      classes

      ChatSession
      RequestUrl
      VertexAIService

      ChatSession
      RequestUrl
      VertexAIError
      VertexAIService

      + VertexAIError

      variables

      27 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      ERRORS
      ERROR_FACTORY
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      25 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      - ERRORS
      - ERROR_FACTORY

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      FirebaseError

      + FirebaseError
      - ErrorFactory

    • FinishReason

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.94 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • FunctionCallingMode

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.95 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • FunctionDeclarationSchemaType

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.68 kB2.96 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • GenerativeModel

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size16.7 kB16.7 kB+30 B (+0.2%)
      size-with-ext-deps35.1 kB35.1 kB+34 B (+0.1%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      classes

      ChatSession
      GenerativeModel
      RequestUrl
      VertexAIService

      ChatSession
      GenerativeModel
      RequestUrl
      VertexAIError
      VertexAIService

      + VertexAIError

      variables

      27 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      ERRORS
      ERROR_FACTORY
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      25 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      - ERRORS
      - ERROR_FACTORY

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      FirebaseError

      + FirebaseError
      - ErrorFactory

    • HarmBlockMethod

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.95 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • HarmBlockThreshold

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.95 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • HarmCategory

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.94 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • HarmProbability

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.95 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • HarmSeverity

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.67 kB2.94 kB-724 B (-19.7%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • POSSIBLE_ROLES

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.71 kB2.99 kB-724 B (-19.5%)
      size-with-ext-deps21.4 kB20.7 kB-703 B (-3.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      16 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      POSSIBLE_ROLES
      Task
      VERTEX_TYPE
      name
      version

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      POSSIBLE_ROLES
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      - ErrorFactory

    • VertexAIError

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size?3.27 kB? (?)
      size-with-ext-deps?21.0 kB? (?)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      functions?

      registerVertex

      ?
      classes?

      VertexAIError
      VertexAIService

      ?
      variables?

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      ?
      enums??

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/app?

      _registerComponent
      registerVersion

      ?
      @firebase/component?

      Component

      ?
      @firebase/util?

      FirebaseError

      ?
    • getGenerativeModel

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size16.7 kB16.8 kB+112 B (+0.7%)
      size-with-ext-deps35.2 kB35.3 kB+116 B (+0.3%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      classes

      ChatSession
      GenerativeModel
      RequestUrl
      VertexAIService

      ChatSession
      GenerativeModel
      RequestUrl
      VertexAIError
      VertexAIService

      + VertexAIError

      variables

      27 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      ERRORS
      ERROR_FACTORY
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      25 dependencies

      BlockReason
      DEFAULT_API_VERSION
      DEFAULT_BASE_URL
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      LANGUAGE_TAG
      PACKAGE_VERSION
      POSSIBLE_ROLES
      SILENT_ERROR
      Task
      VALID_PARTS_PER_ROLE
      VALID_PART_FIELDS
      VALID_PREVIOUS_CONTENT_ROLES
      VERTEX_TYPE
      badFinishReasons
      name
      responseLineRE
      version

      - ERRORS
      - ERROR_FACTORY

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory

      FirebaseError

      + FirebaseError
      - ErrorFactory

    • getVertexAI

      Size

      TypeBase (aa060a7)Merge (c869eaf)Diff
      size3.84 kB3.12 kB-719 B (-18.7%)
      size-with-ext-deps28.8 kB28.1 kB-703 B (-2.4%)

      Dependency

      TypeBase (aa060a7)Merge (c869eaf)Diff
      variables

      15 dependencies

      BlockReason
      DEFAULT_LOCATION
      ERRORS
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      14 dependencies

      BlockReason
      DEFAULT_LOCATION
      FinishReason
      FunctionCallingMode
      FunctionDeclarationSchemaType
      HarmBlockMethod
      HarmBlockThreshold
      HarmCategory
      HarmProbability
      HarmSeverity
      Task
      VERTEX_TYPE
      name
      version

      - ERRORS

      External Dependency

      ModuleBase (aa060a7)Merge (c869eaf)Diff
      @firebase/util

      ErrorFactory
      getModularInstance

      getModularInstance

      - ErrorFactory

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/RfjJaTZxrO.html

@dlarocque dlarocque removed the request for review from hsubox76 May 10, 2024 14:07
@dlarocque dlarocque marked this pull request as draft May 10, 2024 14:07
@dlarocque dlarocque marked this pull request as ready for review May 10, 2024 16:05
@dlarocque dlarocque requested a review from a team as a code owner May 10, 2024 16:05
Copy link
Contributor

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this looks like a lot of comments but the core of this PR was pretty solid, it's a big rewrite of the whole error architecture, thanks for putting in all the work investigating and trying different approaches.

*
* @public
*/
export class VertexAIError extends FirebaseError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have any code in types - for style purposes and it also causes some obscure bugs during build sometimes. Let's move this to src/errors.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want users to be able to import VertexAIError, so I moved the class implementation to src/errors.ts, but am still exporting it from types. Does this approach still cause some bugs during build times?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we export it out of api.ts or index.ts? I guess I'd prefer api.ts since there's a few class exports there already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently export any classes from api.ts- we only have getVertexAI(), and getGenerativeModel(). I feel like it's a bit odd to export an error alongside those. Could we add export './errors' to index.ts?

packages/vertexai/src/types/error.ts Outdated Show resolved Hide resolved
packages/vertexai/src/types/error.ts Outdated Show resolved Hide resolved
packages/vertexai/src/types/error.ts Outdated Show resolved Hide resolved
packages/vertexai/src/api.ts Outdated Show resolved Hide resolved
packages/vertexai/src/requests/response-helpers.ts Outdated Show resolved Hide resolved
packages/vertexai/src/requests/response-helpers.ts Outdated Show resolved Hide resolved
* @param errorDetails - Optional additional details about the error.
*/
constructor(
readonly code: VertexAIErrorCode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized the constructor is already kind of long and only going to get longer as we think of more properties to add. (We already have to add "response" as mentioned in another comment.) Maybe we can put all the optional properties into an object, so it's constructor(code, message, customErrorData) where customErrorData is an object with all the optional properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! since status, statusText, and errorDetails are used only when throwing on HTTP responses, I moved them into a HTTPErrorDetails interface, and accept that as a parameter instead.

New constructor:

constructor(
    readonly code: VertexAIErrorCode,
    readonly message: string,
    readonly httpErrorDetails?: HTTPErrorDetails,
    readonly generateContentResponse?: GenerateContentResponse
  )

New error declaration with http details:

      throw new VertexAIError(
        VertexAIErrorCode.FETCH_ERROR,
        `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`,
        {
          status: response.status,
          statusText: response.statusText,
          errorDetails
        }
      );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should future proof it by making it not HTTPError specific. We might put other details in here in the future not related to HTTP, I don't think we should then create a separate arg for that. I think response should go in here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I renamed httpErrorData to customErrorData, made all the properties optional, and moved generateContentResponse into it.

Since we're making all these properties optional and we expect to add more in the future, I am a little worried our error declarations will start looking like this:

      throw new VertexAIError(
        VertexAIErrorCode.FETCH_ERROR,
        `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`,
        {
          undefined, // unused `status`. must be undefined to "skip over" to the field we want to include
          undefined, // unused `statusText`
          undefined, // unused `response`
          undefined, // unused `customErrorData`
          newErrorField
        }
      );

packages/vertexai/src/types/error.ts Outdated Show resolved Hide resolved
@dlarocque dlarocque requested a review from hsubox76 May 13, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants