Skip to content

semantic-check: fail fast on a tty instead of hanging on stdin - #319

Open
Ar9av wants to merge 1 commit into
mainfrom
fix/semantic-check-tty
Open

semantic-check: fail fast on a tty instead of hanging on stdin#319
Ar9av wants to merge 1 commit into
mainfrom
fix/semantic-check-tty

Conversation

@Ar9av

@Ar9av Ar9av commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

A bare prismor semantic-check on an interactive terminal hangs. Reported as "semantic-check shows an error."

text = args.text; if not text: text = sys.stdin.read() — with no argument (or an empty-string argument, which is falsy) it falls through to sys.stdin.read(), which blocks until EOF. On a real terminal with nobody piping input, the command just sits there with no prompt and no hint; the only way out is Ctrl-D, which then prints error: no text provided. Either way it reads as the tool being broken.

Proven with a real pty (no input sent):

OLD: HUNG — still waiting on stdin after 5.0s
NEW: errored fast in 0.3s

Fix

Guard the stdin fallback with sys.stdin.isatty() — the same pattern prismor unlock already uses. When stdin is a terminal and no text was passed, print usage and exit 1 immediately:

$ prismor semantic-check
error: no text provided
  pass it as an argument:  prismor semantic-check "<text>"
  or pipe it via stdin:     echo "<text>" | prismor semantic-check

Piping (echo … | prismor semantic-check) and the positional-argument path are unchanged.

Testing

  • New pty regression test: a bare invocation on a tty errors fast, never hangs (would hit subprocess.TimeoutExpired against the old code).
  • Fast-error path for empty piped stdin.
  • Both in tests/test_cli.py; verified on st3ve that piped/arg invocations still analyze normally.

A bare `prismor semantic-check` (or an empty-string argument) on an interactive
terminal fell through to `sys.stdin.read()`, which blocks until EOF. With no
argument and nobody piping input, the command just hung with no prompt and no
hint — it reads as the tool being broken. (Verified with a real pty: old code
still waiting after 5s; only Ctrl-D turned it into "no text provided".)

Guard the stdin fallback with `sys.stdin.isatty()`, the same pattern
`prismor unlock` already uses: when stdin is a terminal and no text was given,
print usage and exit 1 immediately. Piping (`echo ... | prismor semantic-check`)
and the positional argument are unchanged.

Tests: pty regression (bare invocation on a tty errors fast, never hangs) plus
the empty-piped-stdin fast-error path, in test_cli.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant