Repository navigation
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This was referenced Aug 5, 2026
Tr00d
approved these changes
Aug 5, 2026
Three packages each declared their own HTTP method enum: `HttpMethod` in postgrest (with a `value` getter), `HttpMethod` in functions_client (without one) and `RequestMethodType` in gotrue, while storage passed method strings around. They now all use a single `HttpMethod` in `supabase_common`. The two public enums collided when re-exported together, which is why `supabase` had to `hide HttpMethod` from postgrest. Both now resolve to the same declaration, so the workaround is gone and `HttpMethod` is finally reachable from `package:supabase` and `package:supabase_flutter`. For consumers: postgrest's `HttpMethod` is unchanged, functions_client's gains `head`, and gotrue's `RequestMethodType` is removed in favour of `HttpMethod` (it was only reachable through `src/`). The compliance matrix pointed `functions.invocation.method_override` at the `HttpMethod` symbol; since the enum now lives in the internal, unscanned `supabase_common`, the entry points at `FunctionsClient.invoke` instead. Part of #1572 (tier 3), under the v3 umbrella #1278.
spydon
force-pushed
the
breaking/supabase-exception-base
branch
from
August 5, 2026 15:14
d68a53b to
aa160d3
Compare
spydon
force-pushed
the
breaking/shared-http-method
branch
from
August 5, 2026 15:14
9a136d8 to
4b05226
Compare
spydon
added a commit
that referenced
this pull request
Aug 6, 2026
…1654) Closes #1652 ## What A Dart enum type names one value rather than the set, so its name should be singular. Five enums were ports of `realtime-js` / `gotrue-js` names instead: | Before | After | Was reachable by consumers? | | --- | --- | --- | | `ChannelStates` | `ChannelState` | No (omitted from the `show` list) | | `ChannelEvents` | `ChannelEvent` | No (omitted from the `show` list) | | `RealtimeListenTypes` | `RealtimeListenType` | No (named in the `hide` clause) | | `PostgresTypes` | `PostgresType` | Yes | | `AuthenticatorAssuranceLevels` | `AuthenticatorAssuranceLevel` | Yes | The three unreachable ones are now annotated `@internal`, which is both the accurate annotation and enough to keep them out of the capability matrix scan. Sweeping the rest of the monorepo's 51 enums turned up one more name that did not read as a noun naming a single value: `LoadTableSnapshots` (storage, Iceberg) is now `TableSnapshotScope`. ## Enum extensions folded in Enums can declare methods and static methods directly, so every extension that only existed to hang helpers off an enum is now part of the enum: - `ChannelEventsExtended` → `ChannelEvent.fromType` / `ChannelEvent.eventName` - `ToType` → `RealtimeListenType.toType` - `PostgresChangeEventMethods` → `PostgresChangeEvent.fromString` / `PostgresChangeEvent.toRealtimeEvent` - `PresenceEventExtended` → `PresenceEvent.fromString` - `AuthChangeEventExtended` → `AuthChangeEvent.fromString` - `GenerateLinkTypeExtended` → `GenerateLinkType.fromString` Those helpers decode wire values, so the folded members carry `@internal`, matching the visibility the extensions already had through the `hide` clauses. The now-unnecessary `hide` entries are dropped from the gotrue and realtime_client exports. `SupabaseEventTypesName` is deliberately left alone: its member is `name()`, which would shadow `Enum.name` if declared on the enum, and both it and its deprecated enum are due for removal anyway. ## Not changed - `SocketStates`, because #1404 already renames it. - `AMRMethod` / `AMREntry` violate Dart's "capitalize acronyms longer than two letters like words" rule (`AmrMethod` / `AmrEntry`). Out of scope here, worth a follow-up. - `RequestMethodType` in gotrue is replaced by the shared `HttpMethod` in #1645. - `FactorStatus`, `RealtimeHeartbeatStatus` and `RealtimeSubscribeStatus` end in `s` but are singular ("status"). - Enum *values* such as `GenerateLinkType.magiclink` and `OtpType.magiclink` are not lowerCamelCase, but they are load-bearing: the wire value is derived from the value name. ## Behaviour None. No enum value changes: `ChannelEvent.eventName()` still produces the same `phx_*` strings and `TableSnapshotScope` still sends `all` / `refs`. ## Capability matrix `PostgresType`, `AuthenticatorAssuranceLevel` and `TableSnapshotScope` are registered under `realtime.subscriptions.postgres_changes`, `auth.mfa.get_authenticator_assurance_level` and `storage.analytics.iceberg_table` (replacing the stale `LoadTableSnapshots` entries). ## Testing - `dart analyze packages examples`: clean - `realtime_client`, `supabase`, `supabase_flutter` suites: pass - `gotrue` MFA, constants and types suites: pass (the rest of the `gotrue` suite has pre-existing failures against my local stack on `main` too) - supabase/sdk `check-api-symbols`, `check-drift` and `validate-compliance` run locally against this branch: all pass <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Breaking Changes** - Renamed authentication assurance-level, realtime channel/event, Postgres type, and table snapshot enums. - Updated related method parameters and response fields to use the new names. - **Improvements** - Simplified enum parsing and conversion APIs. - Corrected public exports for supported types and utilities. - Preserved existing authentication, MFA, realtime, storage, and data-conversion behavior. - **Tests** - Updated coverage for enum parsing, serialization, realtime events, and MFA flows. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
spydon
added a commit
that referenced
this pull request
Aug 13, 2026
Tier 3 of #1572, third of four PRs. Stacked on #1645 (which is stacked on #1644). ## What The same "double the delay, cap it" math existed in three places: | Site | Before | | --- | --- | | `RetryOptions.delay` (supabase_common) | `delayFactor * pow(2, min(attempt, 31)) * jitter`, capped at `maxDelay` | | `RetryTimer.createRetryFunction` (realtime_client) | `firstDelay << min(tries - 1, maxShift)`, capped at `maxDelay`, in milliseconds | | `PostgrestBuilder._defaultRetryDelay` | `Duration(seconds: min(pow(2, attempt), 30))` | All three now call one helper in `supabase_common`: ```dart Duration exponentialBackoff( int attempt, { required Duration initialDelay, required Duration maxDelay, double randomizationFactor = 0, Random? random, }); ``` `attempt` is zero based, so attempt `0` waits `initialDelay` and each attempt after that doubles until `maxDelay`. Jitter is opt-in per caller, since only the storage upload retry uses it today. ## No behaviour change Each call site keeps the delays it had: - realtime keeps its one-based `tries` and its millisecond return type, so `RealtimeClient(reconnectAfterMs: ...)` and the `TimerCalculation` typedef are untouched. It just passes `tries - 1` to the helper. - `RetryOptions.delay` keeps returning `Duration.zero` for attempt `0` and keeps its jitter. - postgrest still starts at one second and caps at thirty. `maxShift` (a public top-level const in `realtime_client`) is removed: the exponent clamp that stops the doubling from overflowing now lives with the shared calculation. It was not registered in the compliance matrix. Realtime's millisecond-based options (`reconnectAfterMs`, `heartbeatIntervalMs`, `longpollerTimeout`) would read better as `Duration`s, but converting them is a separate change; doing only `reconnectAfterMs` here would leave that API half converted. ## Testing New `backoff_test.dart` covers the start delay, the doubling, the cap, the absence of jitter by default and the jitter bounds with an injected `Random`. `realtime_client`'s existing `retry_timer_test.dart` and postgrest's `retry_test.dart` pass unchanged, which is the real check that the delays did not move. `melos analyze` and `melos format` clean; `gotrue`, `postgrest`, `storage_client`, `realtime_client`, `supabase` and `supabase_common` suites pass against the local stack. Capability matrix symbol and drift checks pass. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Improvements** - Standardized retry timing across PostgREST, Realtime, and shared client components. - Retry delays now increase exponentially, start at one second, and cap at 30 seconds. - Added bounded jitter support to help distribute repeated retry attempts more reliably. - Improved protection against overflow and invalid retry-attempt values. - **Tests** - Added coverage for delay growth, maximum limits, jitter behavior, defaults, and invalid inputs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
spydon
added a commit
that referenced
this pull request
Aug 14, 2026
Tier 3 of #1572, last of four PRs. Stacked on #1646 (→ #1645 → #1644). The tier 3 note said the fetch wrappers are shareable in pieces, not as one wrapper, since each is bound to its own exception type. These are the pieces, now in `supabase_common`: | Helper | Replaces | | --- | --- | | `request.sendWith(httpClient)` | `httpClient != null ? httpClient.send(request) : request.send()` in functions, storage (3 sites) and the Iceberg catalog | | `headers.header(name)` | case-insensitive header lookups on a response | | `headers.mediaType` | functions' `(headers['Content-Type'] ?? headers['content-type'] ?? 'text/plain').split(';')[0].trim().toLowerCase()` and the Iceberg catalog's `contentType.contains('application/json')` | | `headers.redacted` | nothing; new, see below | | `tryDecodeJsonObject(body)` | the "decode the error body, fall back to the raw body" dance in storage and postgrest | `supabase_common` gains a dependency on `http` (`^1.6.0`, the constraint every other package already uses). There is deliberately no shared helper for the "set `Content-Type` unless the caller already did" check that storage and functions each had inline. `BaseRequest.headers` is already a case-insensitive map, so once the headers are on the request that check is just `request.headers.putIfAbsent('Content-Type', ...)`, which is what all three call sites now do. The Iceberg catalog moves to it as well, which drops an ordering subtlety there: it previously relied on `...?headers` spreading after a literal `'Content-Type'` key, so a caller who spelled the header with any other casing ended up with two entries rather than an override. ## Two behaviour changes Both follow from setting the content type on the request rather than on a detached map, and both are in functions' `invoke`: - A body given as a `String` now goes out as `text/plain; charset=utf-8` instead of a bare `text/plain`. `Request.body` fills the charset in itself, and the old header copy ran afterwards and overwrote it. - An explicit charset in a caller-supplied `Content-Type` now drives the body encoding, because the header is in place before `Request.body` reads it. Previously the body was always encoded as UTF-8 regardless of what the caller asked for. Relatedly, a multipart request no longer gets a content type from the switch on the body type. It generates its own boundary while being finalized and sets the header itself, so that default never reached the wire. ## Credentials in the request logs Raised in review. The logs interpolated the headers as sent, so `_log.finest` handed the caller's `apikey` and access token to whatever the logger writes to. `headers.redacted` replaces the value of every credential-bearing header with `<redacted>` and keeps the names, since knowing which headers went out is the useful part when reading a log. It is applied to the request logs and the `Initialize with headers:` logs in functions and storage. Those log lines date back to #1042, so this is a pre-existing leak rather than one this PR introduces, but it is fixed here since the shared helper it needs is what this PR is adding. ## Two bugs this surfaces Each has a regression test that fails without the fix. **Postgrest swallowed typed errors for `maybeSingle()`.** The decode and the `maybeSingle` handling shared one `try`/`catch (_)`: ```dart try { final errorJson = jsonDecode(response.body) as Map<String, dynamic>; error = PostgrestException.fromJson(...); if (_maybeSingle) { return _handleMaybeSingleError(response, error); // rethrows `error` for a real failure } } catch (_) { error = PostgrestException(message: response.body, ...); // ...and catches it here } ``` `_handleMaybeSingleError` returns null data for the "0 rows" case and rethrows otherwise, but that rethrow landed in the `catch (_)` and was replaced by a generic exception built from the raw body. So a `maybeSingle()` request that failed for a real reason lost its `errorCode`, `details` and `hint`. Splitting the decode from the handling fixes it. **A JSON error body with unexpected field types crashed.** Removing that catch-all exposed the next layer of the same problem: `PostgrestException.fromJson` cast `code` and `hint` to `String` and required a `String` message, so `{"code": 502, "message": "Bad gateway"}` — a shape gateways really do return — threw a `TypeError` out of the builder. Both `fromJson` factories now read every field defensively, so any JSON object yields an exception. `StorageException.fromJson` had the same casts and the same exposure. The matching storage bug, where a JSON error body that is not an object escaped as a `TypeError`, is fixed in #1644; here its inline guard collapses into `tryDecodeJsonObject`. ## Not converted Postgrest's own send site keeps managing its `Client` explicitly. It has to close a client it created even when the response body fails midway, and `BaseRequest.send` only closes its internal client when the stream completes normally. supabase_auth and postgrest also keep setting `Content-Type` unconditionally rather than defaulting it with `putIfAbsent`: both always JSON-encode the body, so honouring a caller-provided content type there would mislabel the request rather than respect it. The `Initialize with headers:` log in postgrest, realtime_client and supabase_auth still prints the caller's `apikey` and access token. Those packages are outside this refactor, and realtime's `params` map, which carries the `apikey` too, is a `Map<String, dynamic>`, so covering it needs a different shape of helper than the one on `Map<String, String>`. ## Testing New `http_test.dart` in `supabase_common` covers each helper, plus the three regression tests described above. Functions gains a test that a caller-supplied charset is what the body is actually encoded with, a test that no log record carries a credential value while every header name stays readable, and its existing `text/plain` assertion is tightened from `contains` to the full header value. `melos analyze` and `melos format` clean; `dcm analyze` passes (its only two hits are `avoid-inferrable-type-arguments` in `timestamp_test.dart`, which is unchanged from `main`). The `supabase_auth`, `postgrest`, `storage_client`, `functions_client`, `realtime_client`, `supabase`, `supabase_common`, `supabase_flutter`, `supabase_typegen` and `yet_another_json_isolate` suites pass. Capability matrix symbol and drift checks pass. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of malformed, unexpected, or non-object API error responses. - Preserved error details, including status codes, messages, hints, codes, and additional information. - Improved request and response handling across Functions and Storage, including content types, media types, text encoding, and custom HTTP clients. - Redacted credentials from request logs. - **Tests** - Added coverage for malformed errors, multiple-row responses, custom clients, encoding, and HTTP utilities. - **Documentation** - Updated descriptions of shared HTTP functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tier 3 of #1572, second of four PRs. Stacked on #1644, so review that one first.
What
Four packages had four takes on the same enum:
HttpMethod { get, head, post, put, patch, delete }withString get valueHttpMethod { get, post, put, delete, patch }, callers didmethod.name.toUpperCase()RequestMethodType { get, post, put, patch, delete }'GET'/'POST'/'HEAD'strings threaded through the fetch layer and the Iceberg catalogAll four now use one
HttpMethodinsupabase_common:The conflict this removes
supabasecould not re-export both packages' enums, so it carried:Both now resolve to the same declaration, so the
hideis gone andHttpMethodis reachable frompackage:supabaseandpackage:supabase_flutterfor the first time (previouslyfunctions.invoke(method: ...)was usable fromsupabase_flutteronly because functions_client's copy happened to win).Breaking changes
RequestMethodTypeis gone; gotrue'sGotrueFetch.requesttakesHttpMethod. It lived inlib/src/and was not exported frompackage:gotrue.functions_client'sHttpMethodgains aheadvalue and avaluegetter. ExistingHttpMethod.poststyle usage is unaffected.HttpMethodis unchanged in shape, it just moved packages.Storage's changes are internal: its fetch layer and Iceberg REST catalog take
HttpMethodinstead of aString, which removes the last stringly-typed methods in the monorepo.gotrue's request switch gained a
headbranch to stay exhaustive; it sends viaClient.headlike the other verbs.Compliance matrix
functions.invocation.method_overridelisted theHttpMethodsymbol. The enum now lives in the internalsupabase_common, which is excluded from the public API scan, so the entry points atFunctionsClient.invoke(the method that actually takes the override) instead.Testing
melos analyzeandmelos formatclean. Full suites pass forgotrue,postgrest,storage_client,functions_client,realtime_client,supabase,supabase_commonandsupabase_flutter, plus theexamplesanalyzer. The capability matrix symbol, drift and compliance checks pass.