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

Make the FunctionsError class publicly exported #8546

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Sep 30, 2024

We should export the FunctionsError class to users, so that they can perform instanceof checks.

Tested using:

import { FirebaseError, initializeApp } from "firebase/app";
import { FunctionsError, getFunctions, httpsCallable } from "firebase/functions";

const firebaseConfig = {
  /* ... */
};

const app = initializeApp(firebaseConfig);
const functions = getFunctions(app);
(async () => {
  try {
    const addMessage = httpsCallable(functions, 'addMessage'); // Function does not exist
    await addMessage({ text: 'hello' });
  } catch (err) {
    console.log(err instanceof FirebaseError); // true
    console.log(err instanceof FunctionsError); // true
    throw err;
  }
})();

Also added an expect(error).to.be.instanceOf(FunctionsError) to all error checks in the tests.

Fixes #8511

Copy link

changeset-bot bot commented Sep 30, 2024

🦋 Changeset detected

Latest commit: f694fe1

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

This PR includes changesets to release 3 packages
Name Type
@firebase/functions Patch
firebase Patch
@firebase/functions-compat 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 changed the title Make the FunctionsError class publicly exported. Make the FunctionsError class publicly exported Sep 30, 2024
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 30, 2024

Size Report 1

Affected Products

  • @firebase/functions

    TypeBase (beaa4df)Merge (a7b382e)Diff
    browser9.76 kB9.83 kB+68 B (+0.7%)
    esm512.1 kB12.2 kB+69 B (+0.6%)
    main12.8 kB12.9 kB+155 B (+1.2%)
    module9.76 kB9.83 kB+68 B (+0.7%)
  • @firebase/messaging

    TypeBase (beaa4df)Merge (a7b382e)Diff
    browser21.3 kB21.3 kB-84 B (-0.4%)
    esm526.8 kB26.7 kB-84 B (-0.3%)
    main27.4 kB27.4 kB-84 B (-0.3%)
    module21.3 kB21.3 kB-84 B (-0.4%)
  • @firebase/messaging-sw

    TypeBase (beaa4df)Merge (a7b382e)Diff
    main30.4 kB30.4 kB-59 B (-0.2%)
    module23.6 kB23.5 kB-59 B (-0.3%)
  • bundle

    TypeBase (beaa4df)Merge (a7b382e)Diff
    functions (call)32.0 kB32.1 kB+41 B (+0.1%)
    messaging (send + receive)47.0 kB46.9 kB-73 B (-0.2%)
  • firebase

    TypeBase (beaa4df)Merge (a7b382e)Diff
    firebase-compat.js788 kB788 kB-102 B (-0.0%)
    firebase-functions-compat.js8.22 kB8.26 kB+40 B (+0.5%)
    firebase-functions.js12.0 kB12.0 kB+68 B (+0.6%)
    firebase-messaging-compat.js38.4 kB38.3 kB-143 B (-0.4%)
    firebase-messaging-sw.js30.2 kB30.1 kB-71 B (-0.2%)
    firebase-messaging.js28.7 kB28.7 kB-96 B (-0.3%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 30, 2024

Size Analysis Report 1

Affected Products

  • @firebase/functions

    • FunctionsError

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size?2.52 kB? (?)
      size-with-ext-deps?20.3 kB? (?)

      Dependency

      TypeBase (beaa4df)Merge (a7b382e)Diff
      functions?

      registerFunctions

      ?
      classes?

      ContextProvider
      FunctionsError
      FunctionsService

      ?
      variables?

      APP_CHECK_INTERNAL_NAME
      AUTH_INTERNAL_NAME
      DEFAULT_REGION
      FUNCTIONS_TYPE
      MESSAGING_INTERNAL_NAME
      name
      version

      ?
      enums??

      External Dependency

      ModuleBase (beaa4df)Merge (a7b382e)Diff
      @firebase/app?

      _registerComponent
      registerVersion

      ?
      @firebase/component?

      Component

      ?
      @firebase/util?

      FirebaseError

      ?
    • httpsCallable

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size6.13 kB6.17 kB+40 B (+0.7%)
      size-with-ext-deps24.0 kB24.1 kB+41 B (+0.2%)
    • httpsCallableFromURL

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size6.08 kB6.12 kB+40 B (+0.7%)
      size-with-ext-deps24.0 kB24.0 kB+41 B (+0.2%)
  • @firebase/messaging

    • deleteToken

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size12.7 kB12.7 kB-72 B (-0.6%)
      size-with-ext-deps39.5 kB39.4 kB-73 B (-0.2%)
    • getMessaging

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size12.8 kB12.7 kB-73 B (-0.6%)
      size-with-ext-deps46.7 kB46.6 kB-73 B (-0.2%)
    • getToken

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size12.2 kB12.2 kB-72 B (-0.6%)
      size-with-ext-deps39.0 kB38.9 kB-73 B (-0.2%)
    • isSupported

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size12.6 kB12.5 kB-72 B (-0.6%)
      size-with-ext-deps39.3 kB39.2 kB-73 B (-0.2%)
    • onMessage

      Size

      TypeBase (beaa4df)Merge (a7b382e)Diff
      size12.4 kB12.3 kB-72 B (-0.6%)
      size-with-ext-deps39.1 kB39.0 kB-73 B (-0.2%)

Test Logs

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

packages/functions/src/error.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

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

LG with tiny nits, thanks!

| --- | --- | --- |
| [code](./functions.functionserror.md#functionserrorcode) | [FunctionsErrorCode](./functions.md#functionserrorcode) | A standard error code that will be returned to the client. This also determines the HTTP status code of the response, as defined in code.proto. |
| [details](./functions.functionserror.md#functionserrordetails) | unknown | Extra data to be converted to JSON and included in the error response. |
| [(constructor)(code, message, details)](./functions.functionserror.md#functionserrorconstructor) | | Constructs a new instance of the <code>FunctionsError</code> class |
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 want a period here.


A standard error code that will be returned to the client. This also determines the HTTP status code of the response, as defined in code.proto.
## FunctionsError.(constructor)

Copy link
Contributor

Choose a reason for hiding this comment

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

Period here too.

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.

FunctionsError exported as a type only, but implementation exists
4 participants