Core: Add Unrecoverable error at startup for storage init#820
Open
hydra-yse wants to merge 1 commit into
Open
Conversation
JssDWt
reviewed
Apr 23, 2026
roeierez
requested changes
Apr 25, 2026
34b4e2a to
b42c702
Compare
b42c702 to
653646c
Compare
roeierez
requested changes
May 26, 2026
Comment on lines
+131
to
+155
| func connectWithRecovery() async throws -> BreezSdk { | ||
| let storageDir = "./.data" | ||
|
|
||
| let makeRequest = { | ||
| var config = defaultConfig(network: Network.mainnet) | ||
| config.apiKey = "<breez api key>" | ||
| return ConnectRequest( | ||
| config: config, | ||
| seed: .mnemonic(mnemonic: "<mnemonic words>", passphrase: nil), | ||
| storageDir: storageDir | ||
| ) | ||
| } | ||
|
|
||
| do { | ||
| return try await connect(request: makeRequest()) | ||
| } catch { | ||
| if case SdkError.storageError(let recoverable, _) = error, !recoverable { | ||
| // The SDK storage is corrupted and cannot be recovered by retrying. | ||
| // Clear the storage directory and reconnect with fresh storage. | ||
| try? FileManager.default.removeItem(atPath: storageDir) | ||
| return try await connect(request: makeRequest()) | ||
| } | ||
| throw error | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Not sure we want to set this as the default code to use the sdk. If this is the right approach than why not doing it automatically inside the sdk...
Sounds like better to propagate the error upstream to the app level and let the app handle that? Perhaps need some user interaction here?
|
|
||
| ## Handling Initialization Failures | ||
|
|
||
| Some initialization failures indicate that the local SDK storage is corrupted and retrying without action will not help. When {{#name connect}} returns a `StorageError` with `recoverable` set to false, the app must clear the SDK storage directory and retry. |
Member
There was a problem hiding this comment.
Not sure we should be so decisive here using the terms "must clear the sdk storage".
It basically means the storage is corrupted and given it is a rare case perhaps the app needs to upstream this issue to the user and explicitly ask the user to reset (with a clear warning on the local settings).
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.
Closes #815
This PR adds a
CorruptStorageerror variant toSdkError, making migration errors fromconnectmore actionable for the user so they can know when to reset their storage. An example of how to catch the error and reset the storage has also been provided in the docs