haskell: Phase 9 — hk-run-io catches errors and appends to io-lines
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1163,7 +1163,14 @@
|
|||||||
|
|
||||||
(define
|
(define
|
||||||
hk-run-io
|
hk-run-io
|
||||||
(fn (src) (do (set! hk-io-lines (list)) (hk-run src) hk-io-lines)))
|
(fn
|
||||||
|
(src)
|
||||||
|
(do
|
||||||
|
(set! hk-io-lines (list))
|
||||||
|
(guard
|
||||||
|
(e (true (append! hk-io-lines (if (string? e) e (str e)))))
|
||||||
|
(hk-deep-force (hk-run src)))
|
||||||
|
hk-io-lines)))
|
||||||
|
|
||||||
(define hk-stdin-lines (list))
|
(define hk-stdin-lines (list))
|
||||||
|
|
||||||
@@ -1176,7 +1183,9 @@
|
|||||||
(begin
|
(begin
|
||||||
(set! hk-io-lines (list))
|
(set! hk-io-lines (list))
|
||||||
(set! hk-stdin-lines stdin-lines)
|
(set! hk-stdin-lines stdin-lines)
|
||||||
(hk-run src)
|
(guard
|
||||||
|
(e (true (append! hk-io-lines (if (string? e) e (str e)))))
|
||||||
|
(hk-deep-force (hk-run src)))
|
||||||
hk-io-lines)))
|
hk-io-lines)))
|
||||||
|
|
||||||
(define hk-env0 (hk-init-env))
|
(define hk-env0 (hk-init-env))
|
||||||
|
|||||||
@@ -64,12 +64,11 @@
|
|||||||
|
|
||||||
(hk-test
|
(hk-test
|
||||||
"readFile error on missing file"
|
"readFile error on missing file"
|
||||||
(guard
|
(begin
|
||||||
(e (true (>= (index-of e "file not found") 0)))
|
(set! hk-vfs (dict))
|
||||||
(begin
|
(let
|
||||||
(set! hk-vfs (dict))
|
((lines (hk-run-io "main = readFile \"no.txt\" >>= putStrLn")))
|
||||||
(hk-run-io "main = readFile \"no.txt\" >>= putStrLn")
|
(>= (index-of (str lines) "file not found") 0)))
|
||||||
false))
|
|
||||||
true)
|
true)
|
||||||
|
|
||||||
(hk-test
|
(hk-test
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
|||||||
- [x] Partial functions emit proper error messages: `head []` →
|
- [x] Partial functions emit proper error messages: `head []` →
|
||||||
`"Prelude.head: empty list"`, `tail []` → `"Prelude.tail: empty list"`,
|
`"Prelude.head: empty list"`, `tail []` → `"Prelude.tail: empty list"`,
|
||||||
`fromJust Nothing` → `"Maybe.fromJust: Nothing"`.
|
`fromJust Nothing` → `"Maybe.fromJust: Nothing"`.
|
||||||
- [ ] Top-level `hk-run-io` catches `hk-error` tag and returns it as a tagged
|
- [x] Top-level `hk-run-io` catches `hk-error` tag and returns it as a tagged
|
||||||
error result so test suites can inspect it without crashing.
|
error result so test suites can inspect it without crashing.
|
||||||
- [ ] `hk-test-error` helper in `testlib.sx`:
|
- [ ] `hk-test-error` helper in `testlib.sx`:
|
||||||
`(hk-test-error "desc" thunk expected-substring)` — asserts the thunk raises
|
`(hk-test-error "desc" thunk expected-substring)` — asserts the thunk raises
|
||||||
@@ -293,6 +293,19 @@ No OCaml changes are needed. The view type is fully representable as an SX dict.
|
|||||||
|
|
||||||
_Newest first._
|
_Newest first._
|
||||||
|
|
||||||
|
**2026-05-07** — Phase 9 `hk-run-io` catches errors, appends to io-lines:
|
||||||
|
- Wrapped both `hk-run-io` and `hk-run-io-with-input` in `(guard (e (true …)))`
|
||||||
|
that appends the caught exception to `hk-io-lines`. Also added `hk-deep-force`
|
||||||
|
inside the guard so `main`'s thunk actually evaluates (post-lazy-CAFs change
|
||||||
|
it was a thunk, was previously not forced — IO actions never fired in
|
||||||
|
programs that returned the thunk to `hk-run-io`). Test suites now see error
|
||||||
|
output as the last line of `hk-io-lines` instead of crashing.
|
||||||
|
- Updated one io-input test that used an outer `guard` to look for
|
||||||
|
`"file not found"` in the io-lines string instead.
|
||||||
|
- Verified across program-io (10/10), io-input (11/11), program-fizzbuzz
|
||||||
|
(12/12), program-calculator (5/5), program-roman (14/14), program-wordcount
|
||||||
|
(10/10), program-showadt (5/5), program-showio (5/5), eval.sx (64/64).
|
||||||
|
|
||||||
**2026-05-07** — Phase 9 partial functions emit proper error messages:
|
**2026-05-07** — Phase 9 partial functions emit proper error messages:
|
||||||
- Added empty-list catch clauses to `head`, `tail` in the prelude. Added
|
- Added empty-list catch clauses to `head`, `tail` in the prelude. Added
|
||||||
`fromJust`, `fromMaybe`, `isJust`, `isNothing` (the last three were missing).
|
`fromJust`, `fromMaybe`, `isJust`, `isNothing` (the last three were missing).
|
||||||
|
|||||||
Reference in New Issue
Block a user