diff --git a/collects/racket/file.rkt b/collects/racket/file.rkt index 6614cb8a1f..6a768e6704 100644 --- a/collects/racket/file.rkt +++ b/collects/racket/file.rkt @@ -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)))] diff --git a/collects/scribblings/reference/filesystem.scrbl b/collects/scribblings/reference/filesystem.scrbl index ecf9e5572c..4c8e941ed0 100644 --- a/collects/scribblings/reference/filesystem.scrbl +++ b/collects/scribblings/reference/filesystem.scrbl @@ -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