Skip to content

[Bug] getAccount proceeds with file read after createKeypairByName failure causing unhandled ENOENT crash #304

@zakaziko86

Description

@zakaziko86

Bug Description

getAccount in src/lib/actions/BaseAction.ts (lines 130-136)
unconditionally reads the keystore file after calling
createKeypairByName, even if it failed and never created the file.

Root Cause

if (!existsSync(keystorePath)) {
    await this.confirmPrompt(`Account '${accountName}' not found. Would you like to create it?`);
    decryptedPrivateKey = await this.createKeypairByName(accountName, false);
}

keystoreJson = readFileSync(keystorePath, "utf-8");  // line 135: no error check
keystoreData = JSON.parse(keystoreJson);              // line 136

Impact

If createKeypairByName fails for any reason other than
password mismatch (e.g., disk full, permissions error during
writeFileSync), the keystore file is never created. The code
then crashes with an unhandled ENOENT error on line 135
instead of a clear error message.

Suggested Fix

decryptedPrivateKey = await this.createKeypairByName(accountName, false);
if (!existsSync(keystorePath)) {
    this.failSpinner(`Failed to create keystore file for account '${accountName}'`);
    return;
}

File

src/lib/actions/BaseAction.ts lines 130-136
Severity: High

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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