Skip to content

CLI: Improve error messages with "Did you mean…?" suggestions #88

@PetarStoev02

Description

@PetarStoev02

Context

Typos are the #1 source of friction with any CLI. When a user runs w3-kit chian list (instead of chain), or asks for arbtrum (instead of arbitrum), the current error is a flat "not found" — leaving the user to figure out what they typed wrong. A small Levenshtein-based suggestion turns dead ends into wins.

What to build

When the CLI hits an unknown command, subcommand, or chain/token name, compute the closest match (Levenshtein distance ≤ 2) from the set of valid options and append a "Did you mean <suggestion>?" line to the error.

Apply this to at least:

  • Unknown top-level commands
  • Unknown chain names (in chains show <chain> and similar future commands)
  • Unknown flag names

Acceptance criteria

  • Unknown command suggests closest valid command
  • Unknown chain name suggests closest valid chain (only when within Levenshtein ≤ 2)
  • No suggestion is made when nothing is close enough — error remains clear
  • Tests cover at least 3 typo scenarios
  • Suggestion logic lives in a small helper module that's easy to reuse for future commands

Pointers

  • Reference: fastest-levenshtein npm package for the distance calc
  • Pairs well with the chains commands issue

Complexity

🟢 Good first issue

Metadata

Metadata

Assignees

No one assigned

    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