Skip to content

Core: Add Unrecoverable error at startup for storage init#820

Open
hydra-yse wants to merge 1 commit into
mainfrom
yse/unrecoverable-startup
Open

Core: Add Unrecoverable error at startup for storage init#820
hydra-yse wants to merge 1 commit into
mainfrom
yse/unrecoverable-startup

Conversation

@hydra-yse
Copy link
Copy Markdown
Member

@hydra-yse hydra-yse commented Apr 23, 2026

Closes #815
This PR adds a CorruptStorage error variant to SdkError, making migration errors from connect more 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

Comment thread crates/breez-sdk/core/src/error.rs Outdated
Comment thread crates/breez-sdk/core/src/sdk_builder.rs Outdated
Comment thread crates/breez-sdk/core/src/sdk_builder.rs Outdated
@hydra-yse hydra-yse force-pushed the yse/unrecoverable-startup branch from 34b4e2a to b42c702 Compare April 29, 2026 23:12
@hydra-yse hydra-yse requested review from JssDWt and roeierez April 29, 2026 23:13
Copy link
Copy Markdown
Collaborator

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

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

Looking good!

Comment thread crates/breez-sdk/core/src/sdk_builder.rs Outdated
@hydra-yse hydra-yse force-pushed the yse/unrecoverable-startup branch from b42c702 to 653646c Compare May 11, 2026 20:24
@danielgranhao danielgranhao removed their request for review May 21, 2026 13:57
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
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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).

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.

Handle unrecoverable SDK initialization errors

3 participants