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:
parent
2ae6d0c55f
commit
247a51d5bd
|
@ -354,6 +354,11 @@
|
|||
#f))))))])
|
||||
(let ([prefs (with-pref-params
|
||||
(lambda ()
|
||||
(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
|
||||
|
@ -363,14 +368,19 @@
|
|||
(lambda ()
|
||||
(with-input-from-file pref-file read))
|
||||
lock-there)
|
||||
(with-input-from-file pref-file read))))])
|
||||
(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)))]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user