change `get-preference' to treat read errors the same as other bad content

That is, return '(), but also now log an error.
This commit is contained in:
Matthew Flatt 2011-09-27 19:09:16 -06:00
parent 2ae6d0c55f
commit 247a51d5bd
2 changed files with 27 additions and 15 deletions

View File

@ -354,23 +354,33 @@
#f))))))])
(let ([prefs (with-pref-params
(lambda ()
(if use-lock?
(call-with-preference-file-lock
'get-preference
'shared
(lambda ()
(make-lock-file-name pref-file))
(lambda ()
(with-input-from-file pref-file read))
lock-there)
(with-input-from-file pref-file read))))])
(with-handlers ([exn:fail:read? (lambda (exn)
(log-error
(format "error reading preferences: ~a"
(exn-message exn)))
null)])
(if use-lock?
(call-with-preference-file-lock
'get-preference
'shared
(lambda ()
(make-lock-file-name pref-file))
(lambda ()
(with-input-from-file pref-file read))
lock-there)
(with-input-from-file pref-file read)))))])
;; Make sure file content had the right shape:
(if (and (list? prefs)
(andmap (lambda (x)
(and (pair? x) (pair? (cdr x)) (null? (cddr x))))
(and (pair? x)
(symbol? (car x))
(pair? (cdr x))
(null? (cddr x))))
prefs))
prefs
null)))))
(begin
(log-error "preference file content is not a list of symbol--value lists")
null))))))
(let* ([fn (path->complete-path
(or filename
(find-system-path 'pref-file)))]

View File

@ -937,11 +937,13 @@ read an @elemref["old-prefs"]{old preferences file}, and then a
collection, instead. If none of those files exists, the preference set
is empty.
The preference file should contain a symbol-keyed association list
(written to the file with the default parameter settings). Keys
The preference file should contain a list of symbol--value lists
written with the default parameter settings. Keys
starting with @racket[racket:], @racket[mzscheme:], @racket[mred:],
and @racket[plt:] in any letter case are reserved for use by Racket
implementers.
implementers. If the preference file does not contain a list
of symbol--value lists, an error is logged via @racket[log-error]
and @racket[failure-thunk] is called.
The result of @racket[get-preference] is the value associated with
@racket[name] if it exists in the association list, or the result of