diff options
| author | Arun Isaac | 2026-04-12 04:01:33 +0100 |
|---|---|---|
| committer | Arun Isaac | 2026-04-12 04:06:05 +0100 |
| commit | 5bdc331408505d8264c6d5d31ba1b3fb29c0e69b (patch) | |
| tree | ef43b82120f1946fda115d20534f836a04135cf1 | |
| parent | abf1708cd4a06bce29f628bca83c5ab92c0ede78 (diff) | |
| download | kaagum-5bdc331408505d8264c6d5d31ba1b3fb29c0e69b.tar.gz kaagum-5bdc331408505d8264c6d5d31ba1b3fb29c0e69b.tar.lz kaagum-5bdc331408505d8264c6d5d31ba1b3fb29c0e69b.zip | |
Error out when reading non-existent files.
| -rw-r--r-- | kaakaa/tools/base.scm | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/kaakaa/tools/base.scm b/kaakaa/tools/base.scm index 6b3f3fe..e726c14 100644 --- a/kaakaa/tools/base.scm +++ b/kaakaa/tools/base.scm @@ -39,18 +39,25 @@ Line numbers start from 1. Output is the raw file contents without line numbers. #:type "integer" #:description "Read up to this line number (inclusive). Default is the last line of the file."))) #:proc (lambda* (#:key path (start-line 1) end-line) - (call-with-input-file path - (cut port-transduce - (compose (tdrop (1- start-line)) - (if end-line - (ttake (- end-line (1- start-line))) - (tmap identity)) - (tlog (lambda (result input) - (display input) - (newline)))) - (const #t) - get-line - <>))) + (cond + ((not (file-exists? path)) + (format (current-output-port) + "Error: File ~a does not exist~%" + path) + (exit #f)) + (else + (call-with-input-file path + (cut port-transduce + (compose (tdrop (1- start-line)) + (if end-line + (ttake (- end-line (1- start-line))) + (tmap identity)) + (tlog (lambda (result input) + (display input) + (newline)))) + (const #t) + get-line + <>))))) #:title (lambda* (#:key path (start-line 1) end-line) (format #f "read ~a:~a-~a" path start-line (or end-line ""))) |
