Skip to content

[Bug] setNetwork treats empty string argument as valid input bypassing interactive prompt #306

@zakaziko86

Description

@zakaziko86

Bug Description

setNetwork in src/commands/network/setNetwork.ts (lines 46-60)
incorrectly handles empty string input, bypassing the interactive
prompt and showing a malformed error message.

Root Cause

async setNetwork(networkName?: string): Promise<void> {
    if (networkName || networkName === "") {  // empty string enters this branch
      if (!networks.some(n => n.name === networkName || n.alias === networkName)) {
        this.failSpinner(`Network ${networkName} not found`);  // displays "Network  not found"
        return;
      }
    }
    // interactive prompt — never reached for empty string
}

Impact

When user runs genlayer network set "", the empty string
enters the non-interactive branch. No network matches empty
string, so error displays "Network not found" (with blank space).
The interactive prompt is never shown, confusing the user.

Suggested Fix

// Change condition from:
if (networkName || networkName === "") {
// To:
if (networkName) {  // falsy check — sends empty string to interactive prompt

File

src/commands/network/setNetwork.ts lines 46-60
Severity: Medium

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