From 045cf69ba4b26a17bd20b1c2f5677fa099851594 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 12 Apr 2013 14:58:01 -0600 Subject: [PATCH] racket/enter: fix exception handling & propagation for `enter!' Merge to v5.3.4 (cherry picked from commit 9a52894b8bed6193b44b217cae3a5532ae2eb7bc) --- collects/racket/enter.rkt | 31 ++++++++++++++++++++++--------- collects/tests/racket/enter.rkt | 9 +++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/collects/racket/enter.rkt b/collects/racket/enter.rkt index 630bbc9ed6..12d333a5e1 100644 --- a/collects/racket/enter.rkt +++ b/collects/racket/enter.rkt @@ -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)))) diff --git a/collects/tests/racket/enter.rkt b/collects/tests/racket/enter.rkt index eff20c87f2..6561df64e5 100644 --- a/collects/tests/racket/enter.rkt +++ b/collects/tests/racket/enter.rkt @@ -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)