Skip to content

feat(functions)!: make FunctionException a sealed class - #1723

Open
YadneshTeli wants to merge 1 commit into
supabase:mainfrom
YadneshTeli:feat/sealed-function-exception
Open

feat(functions)!: make FunctionException a sealed class#1723
YadneshTeli wants to merge 1 commit into
supabase:mainfrom
YadneshTeli:feat/sealed-function-exception

Conversation

@YadneshTeli

@YadneshTeli YadneshTeli commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

Makes FunctionException a sealed class in packages/functions_client/lib/src/types.dart so consumers can perform compile-time checked exhaustive switch expressions over all Edge Function failure modes:

  • FunctionsFetchException: Network/transport error before reaching the Edge Function.
  • FunctionsApiException (formerly FunctionsHttpException, renamed in refactor!: spell out abbreviations in the public API #1712): Edge Function returned a non-2xx status code.
  • FunctionsRelayException: Error returned by the Supabase relay (x-relay-error).

Example:

try {
  await supabase.functions.invoke('hello');
} on FunctionException catch (error) {
  final message = switch (error) {
    FunctionsFetchException() => 'Network failure',
    FunctionsRelayException() => 'Relay error',
    FunctionsApiException()   => 'Function returned ${error.statusCode}',
  };
}

Breaking Changes

sealed implies abstract, which means:

  • External packages can no longer directly instantiate a bare FunctionException (e.g. in tests/mocks) or subclass/implement it.
  • Consumers should instantiate/match on one of the concrete subtypes instead (FunctionsFetchException, FunctionsApiException, FunctionsRelayException).

Documented in MIGRATION.md.

Verification

  • melos analyze: 0 issues across all 20 packages
  • melos format: 0 files changed
  • Unit tests: functions_client (51 tests) and supabase tests all pass

Closes #1550

@YadneshTeli
YadneshTeli requested a review from a team as a code owner August 14, 2026 20:07
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c6941d3e-0160-44b4-aa87-dc4e5d0c75c3

📥 Commits

Reviewing files that changed from the base of the PR and between a0be827 and 59e013b.

📒 Files selected for processing (3)
  • MIGRATION.md
  • packages/functions_client/lib/src/types.dart
  • packages/functions_client/test/functions_dart_test.dart

📝 Walkthrough

Walkthrough

FunctionException is now a sealed class with three documented failure subtypes. Migration guidance explains the breaking changes and exhaustive pattern matching. Tests verify matching for fetch, relay, and API exceptions.

Changes

FunctionException sealing

Layer / File(s) Summary
Sealed exception contract and migration guidance
packages/functions_client/lib/src/types.dart, packages/functions_client/test/functions_dart_test.dart, MIGRATION.md
FunctionException is sealed. Documentation identifies FunctionsFetchException, FunctionsRelayException, and FunctionsApiException. Migration guidance describes exhaustive matching and restrictions on external construction or extension. Tests cover all three subtypes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 59e01

This PR makes FunctionException sealed and documents the resulting breaking change while preserving the listed concrete failure types; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

Suggested labels: v3

Suggested reviewers: spydon

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR makes FunctionException sealed, but it documents and tests FunctionsApiException instead of the linked issue's required FunctionsHttpException subtype. Align the implementation, documentation, and tests with issue #1550, or update the linked issue if FunctionsApiException is the intended replacement for FunctionsHttpException.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The migration documentation and exhaustive pattern-matching test directly support the sealed-class change and remain within the linked issue scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary breaking change: making FunctionException a sealed class.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Make FunctionException a sealed class for v3

1 participant