Skip to content

fix: handle non-FlutterFire-generated firebase_options.dart gracefully#430

Open
solvejet-team wants to merge 2 commits intoinvertase:mainfrom
solvejet-team:fix/handle-non-standard-firebase-options
Open

fix: handle non-FlutterFire-generated firebase_options.dart gracefully#430
solvejet-team wants to merge 2 commits intoinvertase:mainfrom
solvejet-team:fix/handle-non-standard-firebase-options

Conversation

@solvejet-team
Copy link
Copy Markdown

Description

When firebase_options.dart exists but was not generated by FlutterFire CLI
(e.g. a placeholder file using UnimplementedError instead of UnsupportedError),
the CLI crashes with Exception: UnsupportedError not found in <platform>.

Root Cause

_updateExistingConfigurationFile() assumes the existing file contains
UnsupportedError throw blocks. If the file doesn't match, it throws
instead of falling back gracefully.

Fix

Added _isFlutterFireGeneratedFile() check in write(). If the existing
file wasn't generated by FlutterFire CLI, it regenerates from scratch
instead of attempting an in-place update.

Tests

All 27 existing unit tests pass.

Fixes #422
Fixes #382

Type of Change

  • feat -- New feature (non-breaking change which adds functionality)
  • 🛠️ fix -- Bug fix (non-breaking change which fixes an issue)
  • ! -- Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 refactor -- Code refactor
  • ci -- Build configuration change
  • 📝 docs -- Documentation
  • 🗑️ chore -- Chore

When firebase_options.dart exists but was not generated by FlutterFire CLI
(e.g. a placeholder file using UnimplementedError instead of UnsupportedError),
the CLI crashes with "Exception: UnsupportedError not found in <platform>".

This fix checks whether the existing file matches the expected FlutterFire
format before attempting an in-place update. If it does not match, the file
is regenerated from scratch.

Fixes invertase#422
Fixes invertase#382
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a verification step to ensure existing configuration files were generated by the FlutterFire CLI before attempting updates, allowing placeholder files to be correctly overwritten. It also includes various code formatting improvements and more descriptive error handling. A review comment suggests a more robust implementation for the file generation check by verifying the presence of the standard CLI header comment.

Comment on lines +72 to +80
/// Checks whether the existing file was generated by FlutterFire CLI
/// by looking for the expected structure (platform switch/if blocks).
/// Returns false for placeholder or manually written files.
bool _isFlutterFireGeneratedFile(File file) {
final contents = file.readAsStringSync();
return contents.contains('DefaultFirebaseOptions') &&
(contents.contains('kIsWeb') ||
contents.contains('defaultTargetPlatform'));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current check for whether a file is generated by FlutterFire CLI is based on the presence of certain keywords. This might be brittle and could lead to false positives if a user's placeholder file happens to contain these keywords.

A more robust method would be to check for the specific comment header // File generated by FlutterFire CLI. that this tool adds to the beginning of every generated file. This is a much stronger and more reliable signal that the file was auto-generated.

  /// Checks whether the existing file was generated by FlutterFire CLI
  /// by looking for the header comment.
  /// Returns false for placeholder or manually written files.
  bool _isFlutterFireGeneratedFile(File file) {
    final contents = file.readAsStringSync();
    return contents.startsWith('// File generated by FlutterFire CLI.');
  }

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

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.

[bug]: Exception: UnsupportedError not found in android UnsupportedError not found in android

2 participants