racket/enter: fix exception handling & propagation for `enter!'

Merge to v5.3.4
This commit is contained in:
Matthew Flatt 2013-04-12 14:58:01 -06:00
parent 9420855879
commit 9a52894b8b
2 changed files with 31 additions and 9 deletions

View File

@ -35,15 +35,28 @@
(define (do-enter! mod flags)
(let ([flags (check-flags flags)])
(if mod
(let* ([none "none"]
[exn (with-handlers ([void (lambda (exn)
(log-enter!-error "~a" (exn-message exn)))])
(enter-require mod flags)
none)]
[ns (module->namespace mod)])
(current-namespace ns)
(unless (memq '#:dont-re-require-enter flags)
(namespace-require 'racket/enter))
(let* ([none (gensym)]
[exn (with-handlers ([void (lambda (exn) exn)])
(if (module-path? mod)
(enter-require mod flags)
(raise-argument-error 'enter! "module-path?" mod))
none)])
;; Try to switch to the module namespace,
;; even if there was an exception, because the
;; idea is to allow debugging from inside the
;; module. If any excepiton happens in trying to
;; switch to the declared module, log that as
;; an internal exception.
(with-handlers ([void (lambda (exn)
(if (exn? exn)
(log-enter!-error (exn-message exn))
(log-enter!-error "~s" exn)))])
(when (and (module-path? mod)
(module-declared? mod #f))
(let ([ns (module->namespace mod)])
(current-namespace ns)
(unless (memq '#:dont-re-require-enter flags)
(namespace-require 'racket/enter)))))
(unless (eq? none exn) (raise exn)))
(current-namespace orig-namespace))))

View File

@ -1,4 +1,13 @@
#lang racket
(require racket/enter)
;; Make sure that when a module has a syntax error, we still
;; switch into the module's namespace:
(parameterize ([current-namespace (make-base-namespace)])
(eval '(module f racket/base (define f 'yes) (raise-user-error 'oops "broken")))
(with-handlers ([exn:fail:user? void]) (enter! 'f))
(unless (eq? 'yes (eval 'f))
(error "not in f?")))
;; Make sure that `enter!' can work on lots of modules:
(enter! slideshow/pict)