fix(cli): preserve eval runtime failure stdout and exit codes#947
Merged
fix(cli): preserve eval runtime failure stdout and exit codes#947
Conversation
When a compiled Hew program exits non-zero during `hew eval`, any stdout
produced before the failure was silently discarded and `hew eval` always
exited 1 regardless of the child's actual exit code.
Changes:
- `process.rs`: Add `exit_code: i32` to `BinaryRunOutcome::Failed`;
populated from `ExitStatus::code().unwrap_or(1)` at the wait site.
- `eval/repl.rs`: Add `RuntimeFailure { stdout, exit_code }` to both
`CompiledEvalError` and `CliEvalError`. `run_inprocess_compiled` now
returns `RuntimeFailure` instead of swallowing stdout; child stderr is
written directly to the parent's stderr at that layer. All three
`CompiledEvalError → CliEvalError` mapping sites and the interactive
`handle_interactive_input` handler are updated exhaustively.
- `eval/mod.rs`: `exit_eval_error` handles `RuntimeFailure` by printing
captured stdout then calling `std::process::exit(exit_code)` so the
child's exit code is propagated rather than hard-coded to 1.
- `test_runner/runner.rs`: Exhaustive pattern update for the new field
(`exit_code` is not used by the test runner; ignored with `..`).
- `tests/eval_e2e.rs`: Three focused regression tests covering (1) inline
eval exit-code propagation, (2) file-mode exit-code propagation, and (3)
file-mode pre-failure stdout preservation.
…ntract The native eval path was fixed in the previous commit to preserve pre-failure stdout and propagate the child exit code via `RuntimeFailure`. The WASM path (`hew eval --target wasm32-wasi`) had the same bug: `WasiCapturedOutcome::Failed` carried only `stderr` and mapped to `CompiledEvalError::Message`, so `exit_eval_error` took the generic branch and always exited 1 while stdout was discarded. Changes: - `wasi_runner.rs`: Add `stdout: String` and `exit_code: i32` to `WasiCapturedOutcome::Failed`; `run_module_captured` now forwards them from the underlying `BinaryRunOutcome::Failed` fields (already present after the previous fix). - `eval/repl.rs`: `run_wasm_eval_compiled` maps `WasiCapturedOutcome::Failed` to `CompiledEvalError::RuntimeFailure` (writing the module's stderr directly to parent stderr, identical to the native path), so the propagation chain through `CliEvalError` and `exit_eval_error` works for WASM without further changes. - `tests/eval_e2e.rs`: Three focused WASM parity regressions mirroring the native tests: (1) inline WASM exit-code propagation, (2) file-mode WASM exit-code propagation, (3) file-mode WASM pre-failure stdout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hew evalruntime failures--target wasm32-wasiso native and WASM paths stay alignedValidation