fix!: onError not called if cacheFlags is true and api is not reachable#365
fix!: onError not called if cacheFlags is true and api is not reachable#365talissoncosta merged 3 commits intomainfrom
Conversation
…ache Reproduces issue #348 where onError is not called when cacheFlags is true, no cache exists, and the API fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When cacheFlags is true but no cache exists, API errors were silently swallowed. Now properly calls onError and rejects init() when there are no fallback flags available. BREAKING CHANGE: When cacheFlags is true and no cache exists, init() will now reject if the API fails and no defaultFlags are provided. Previously, errors were silently swallowed. Fixes #348 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@talissoncosta Does this really have to be a breaking change release? Normally fixes are considered patch releases. |
|
@jhoermann Good question! Normally yes, but @kyle-ssg raised a valid concern: this fix changes behavior in a way that could break existing apps. Before: When cacheFlags: true and API fails with no cache, init() silently succeeds and onError is never called. The issue is that users might have onError callbacks that throw or have side effects they didn't expect to trigger in this scenario. Since their apps currently "work" (even if incorrectly), this fix could cause unexpected crashes. We decided to err on the side of caution with a major bump. Happy to discuss if you think a patch is more appropriate! |
Ok got it 👍 |
Summary
onErrorcallback not being called whencacheFlags: true, no cache exists, and API failsProblem
When
cacheFlags: trueis set but no cache exists yet (first-time user), and the API fails, theonErrorcallback was never called. The error was silently swallowed in the catch block atflagsmith-core.ts:517-519.Before this fix:
init()resolves successfully (even though API failed)onErroris NOT calledAfter this fix:
init()rejects with the API erroronErrorIS called with the errorcacheFlags: falseand API failsBreaking Change
This is a behavior change for users with
cacheFlags: truewhen:Previously
init()would silently succeed; now it properly rejects.Migration: Users relying on silent failure should add error handling to their
init()call or usedefaultFlagsas a fallback.Test plan
Fixes #348