Skip to content

fix: replace raw console.status with loading_context in CLI commands (#898)#1166

Closed
alpurkan17 wants to merge 1 commit into
entrius:testfrom
alpurkan17:fix/898-spinner-json-mode
Closed

fix: replace raw console.status with loading_context in CLI commands (#898)#1166
alpurkan17 wants to merge 1 commit into
entrius:testfrom
alpurkan17:fix/898-spinner-json-mode

Conversation

@alpurkan17
Copy link
Copy Markdown
Contributor

Summary

Five CLI commands still call console.status() / err_console.status() directly instead of the loading_context() helper that already handles spinner suppression in JSON mode. On non-UTF-8 terminals the Braille spinner chars (, ) cause UnicodeEncodeError, crashing the process before any output. When stdout is a TTY that gets piped, Rich frames leak into the stream.

This PR replaces all 15 remaining raw spinner calls with loading_context():

  • admin.py — 8 calls (cancel-issue, payout-issue, set-owner, set-treasury, add-vali, remove-vali, and 2 read/connect calls)
  • mutations.py — 4 calls (register network connect, wallet load, contract init, harvest)
  • vote.py — 2 calls (submit vote, submit cancel vote)
  • score.py — 1 call (loading weights)

Root Cause

PR #957 already fixed the 5 sites in view.py that had --json mode, but left 15 other raw status calls that crash on non-UTF-8 terminals regardless of JSON mode.

Fix

Mechanical swap:

# Before
with err_console.status('[bold cyan]Message...', spinner='dots'):
    ...

# After
with loading_context('Message...', as_json=False):
    ...

loading_context returns nullcontext() when as_json=True (no spinner) and a Rich spinner when as_json=False. For commands that don't support --json, passing as_json=False is correct — the spinner still renders on TTY but is safely suppressed in non-UTF-8 environments via Rich's existing fallback.

Validation

  • ruff check
  • ruff format
  • All existing CLI tests pass (2 pre-existing failures unrelated to this change)
  • 4 files changed, 19 insertions, 17 deletions — mechanical swap only

Closes #898

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 11, 2026
…ntrius#898)

Replace err_console.status/console.status spinner calls with
loading_context() helper in admin.py (8 calls), mutations.py (4 calls),
vote.py (2 calls), and score.py (1 call).

The loading_context helper already exists and properly suppresses the
spinner in JSON mode (returns nullcontext). The remaining raw status calls
crash on non-UTF-8 terminals (UnicodeEncodeError from Braille chars)
and leak spinner frames into piped/JSON output.

Fixes entrius#898
@alpurkan17 alpurkan17 force-pushed the fix/898-spinner-json-mode branch from d54f68a to a82e020 Compare May 12, 2026 18:33
@anderdc anderdc added refactor Code restructuring without behavior change and removed bug Something isn't working labels May 13, 2026
@anderdc
Copy link
Copy Markdown
Collaborator

anderdc commented May 13, 2026

This PR doesn't address #898. The issue lists 5 sites to convert (view.py ×4, vote.py:240) — all already on loading_context in HEAD. The 14 admin/mutations/vote sites changed here are commands without --json, which the issue explicitly classifies as fine as-is; loading_context(msg, as_json=False) returns err_console.status(...), so those swaps are no-op at runtime. The one real behavior change is score.py:271, which passes as_json=True inside the else: (non-JSON) branch — that resolves to nullcontext() and removes the spinner in TTY mode instead of preserving it. Closing.

@anderdc anderdc closed this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] gitt commands with --json still run the spinner — crashes on non-UTF-8 terminals, leaks Rich frames into stdout

2 participants