Skip to content

bug: Replace panic-inducing .unwrap() with graceful error handling in ledger_lockfile #1186

@Abhilashpatel12

Description

@Abhilashpatel12

Report

During the validator startup sequence, the application acquires a lock on the ledger directory by creating/opening a ledger.lock file. Currently, if this operation fails (e.g., due to insufficient directory permissions or a full disk), the application crashes with a Rust panic because of an .unwrap() call in magicblock-api/src/ledger.rs.

Location:

rust
// magicblock-api/src/ledger.rs
pub fn ledger_lockfile(ledger_path: &Path) -> RwLock {
let lockfile = ledger_path.join("ledger.lock");
fd_lock::RwLock::new(
OpenOptions::new()
.write(true)
.create(true)
.truncate(false)
.open(lockfile)
.unwrap(), // Panics if file cannot be created/opened
)
}
Expected Behavior
The validator should catch the std::io::Error and exit gracefully with a user-friendly error message, informing the node operator to check their directory permissions or disk space, rather than terminating with an unhelpful panic backtrace.

Commit / version

ee15b9d

Environment

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions