cmd: the state-file delete prompt and integration Run commands exit 0 on failure

Open
#26,271 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
cli

Research direction

Start with the prompt in DeleteStateSnapshots in cmd/utils/app/snapshots_cmd.go around lines 1052-1061, where os.Exit(0) is called on read failure. Then look at the integration commands in cmd/integration/commands that use cobra Run and return errors only by logging. Done means a prompt read error exits non-zero, and commands return errors through RunE with defer debug.Exit() in place, verified by running rm-state and rebuild with closed stdin.

Written by the indexing model from the issue text.

Description

Commands that fail or do nothing still exit 0, so scripts and unattended runs cannot tell them from a finished run.

  • DeleteStateSnapshots (cmd/utils/app/snapshots_cmd.go:1052-1061) calls os.Exit(0) when its prompt cannot read an answer (EOF from a closed stdin, or input that is not a number), the same as for the "Exit" choice. erigon seg rm-state and integration commitment rebuild without --yes share it.
  • Reported in the #24304 review (https://github.com/erigontech/erigon/pull/24304#pullrequestreview-5891007601): after erigon seg rm-state --domain=commitment, rebuild without --yes read EOF at the "remove 0 files?" prompt, did nothing and exited 0.
  • Most commands in cmd/integration/commands use cobra Run (23 of 30 with #24304); each that logs an error and returns exits 0. #24304 moves commitment rebuild to RunE.
  • Fix: exit non-zero on a prompt read error; return errors from the remaining Run commands. Each new RunE needs defer debug.Exit(), as rebuild has in #24304: cobra returns before PersistentPostRun when RunE fails, so --pprof.cpuprofile and --trace output is never finished.
Dominant language
Go
Stars
3.6k
Forks
1.6k
Avg merge
1d 17h
Merged PRs (30d)
820

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from erigontech/erigon

All issues in erigontech/erigon

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.