镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(functions): guard null and non-string error details in platformExceptionToFirebaseFunctionsException - #18827

Open
cynthiajoan wants to merge 1 commit into
firebase:mainfrom
cynthiajoan:agent/null-message-cloud_functions_platform_interface-FN-3
Open

cynthiajoan wants to merge 1 commit into
firebase:mainfrom
cynthiajoan:agent/null-message-cloud_functions_platform_interface-FN-3

Conversation

@cynthiajoan

Copy link
Copy Markdown
Contributor

Description

Fixes a null-check crash (message!) and unchecked details casts in platformExceptionToFirebaseFunctionsException (packages/cloud_functions/cloud_functions_platform_interface/lib/src/method_channel/utils/exception.dart, lines 34–59).

Why this is needed

  • When the native Android or iOS Cloud Functions plugin rejects a callable invocation with a PlatformException, platformExceptionToFirebaseFunctionsException previously assumed:
    1. platformException.details is either null or a Map (Map<String, dynamic>.from(platformException.details) at line 35).
    2. details['code'] and details['message'] are String? when non-null.
    3. Either details['message'] or platformException.message is non-null, passing message: message! (line 55) to FirebaseFunctionsException (whose message parameter is String?).
  • When a callable fails without an error message (for example, a native error whose localizedDescription / getMessage() is null and details['message'] is null), message! throws a TypeError (Null check operator used on a null value) instead of returning a FirebaseFunctionsException. Similarly, if details is not a Map or contains non-String code/message values, the conversion throws a TypeError before the caller's on FirebaseFunctionsException catch handler can run.

Why this does not break existing SDK behavior

  • When platformException.details is a Map with String code and message (or when platformException.message is a non-null String), the returned FirebaseFunctionsException has the exact same code, message, details (additionalData), and stackTrace as before.
  • Only inputs that previously threw an uncaught TypeError inside the exception converter (details not a Map, non-String details['code']/details['message'], or both details['message'] and platformException.message being null) now safely fall back (message: message ?? code, matching _flutterfire_internals's platformExceptionToFirebaseException).

Verification

  • Red (before fix, on 387c707b2 with only the new tests): flutter test --no-pub test/method_channel/method_channel_https_callable_test.dart fails with:
    type 'Null' is not a subtype of type 'String' in type cast (package:cloud_functions_platform_interface/src/method_channel/utils/exception.dart:49:20)
    type 'int' is not a subtype of type 'String' (package:cloud_functions_platform_interface/src/method_channel/utils/exception.dart:43:12)
    
  • Green (with fix, at d81d4b71a):
    • dart format --output=none --set-exit-if-changed . (0 changes)
    • dart analyze --fatal-infos . (0 issues)
    • flutter test --no-pub in cloud_functions_platform_interface (28 passed, 0 failed)

Related Issues

N/A

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

This branch has not been deployed

No deployments
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.

1 participant