help desk now reports bad hdindex and keywords files when searching

svn: r1291

original commit: 09aba062b7f49bbfc9b46f06fc0ea0e91318f164
This commit is contained in:
Robby Findler 2005-11-12 03:36:35 +00:00
parent b7a42527dd
commit 0b0ab3ecc8

View File

@ -116,11 +116,8 @@
html-keywords html-keywords
doc doc
(lambda () (lambda ()
(with-handlers ([exn:fail:read? (λ (x) null)]
[exn:fail:filesystem? (λ (x) null)])
(transform-keywords (transform-keywords
(with-input-from-file (build-path doc "keywords") (build-path doc "keywords")))))
read))))))
(define html-indices (make-hash-table 'equal)) (define html-indices (make-hash-table 'equal))
(define (load-html-index doc) (define (load-html-index doc)
@ -128,53 +125,65 @@
html-indices html-indices
doc doc
(lambda () (lambda ()
(with-handlers ([exn:fail:read? (lambda (x) null)]
[exn:fail:filesystem? (lambda (x) null)])
(transform-hdindex (transform-hdindex
(with-input-from-file (build-path doc "hdindex") (build-path doc "hdindex")))))
read))))))
;; transform-hdindex : any -> (listof (list string path string string) ;; transform-hdindex : any -> (listof (list string path string string)
;; makes sure the input from the file is well-formed and changes ;; makes sure the input from the file is well-formed and changes
;; the bytes to paths. ;; the bytes to paths.
(define (transform-hdindex l) (define (transform-hdindex filename)
(let/ec k (verify-file filename
(let ([fail (lambda () (k '()))]) (λ (l)
(unless (list? l) (fail))
(map (lambda (l)
(match l (match l
[`(,(? string? index) [`(,(? string? index)
,(? string? file) ,(? string? file)
,(? string? label) ,(? string? label)
,(? string? title)) ,(? string? title))
(list index #t]
file
label
title)]
[else [else
(fail)])) #f]))))
l))))
;; transform-keywords : any -> (listof (list string string path string string) ;; transform-keywords : any -> (listof (list string string path string string)
;; as with transform-hdindex ;; as with transform-hdindex
(define (transform-keywords l) (define (transform-keywords filename)
(let/ec k (verify-file filename
(let ([fail (lambda () (k '()))]) (λ (l)
(unless (list? l) (fail))
(map (lambda (l)
(match l (match l
[`(,(? string? keyword) [`(,(? string? keyword)
,(? string? result) ,(? string? result)
,(? path-string? file) ,(? path-string? file)
,(? string? label) ,(? string? label)
,(? string? title)) ,(? string? title))
(list keyword #t]
result [else
file #f]))))
label
title)] (define (verify-file filename ele-ok?)
[else (fail)])) (let/ec k
l)))) (let ([fail (lambda (why)
(fprintf (current-error-port)
"loading docs from ~a failed: ~a\n"
(path->string filename)
why)
(k '()))])
(with-handlers ([exn:fail:read? (lambda (x)
(fail
(format "read error when opening the file ~a"
(exn-message x))))]
[exn:fail:filesystem?
(lambda (x)
(fail (format
"filesystem error when opening the file ~a"
(exn-message x))))])
(let ([l (if (file-exists? filename)
(call-with-input-file filename read)
'())])
(unless (list? l) (fail "not a list"))
(for-each (lambda (l)
(unless (ele-ok? l)
(fail (format "line ~s is malformed" l))))
l)
l)))))
(define (parse-txt-file doc ht handle-one) (define (parse-txt-file doc ht handle-one)
(with-hash-table (with-hash-table
@ -351,7 +360,6 @@
(unless (< hit-count MAX-HIT-COUNT) (unless (< hit-count MAX-HIT-COUNT)
(maxxed-out))) (maxxed-out)))
; Keyword search ; Keyword search
(let ([keys (case doc-kind (let ([keys (case doc-kind
[(html) (load-html-keywords doc)] [(html) (load-html-keywords doc)]