From 311fe6f3b2fc13d020e13c16f78620f660d242e8 Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Sat, 14 Mar 2015 16:27:25 -0400 Subject: [PATCH] Don't kill the REPL due to keymap errors. Restores the default ignore behavior of the REPL if a key sequence does not match anything. Also wraps the matched functions in a try/catch block when the user has made a mistake in keymap construction. Fixes #10397. --- base/LineEdit.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/base/LineEdit.jl b/base/LineEdit.jl index c190bc9ad6d9c..30f7aca305204 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -856,8 +856,6 @@ function postprocess!(dict::Dict) # needs to be done first for every branch if haskey(dict, '\0') add_specialisations(dict, dict, 1) - else - dict['\0'] = (args...)->error("Unrecognized input") end for (k,v) in dict k == '\0' && continue @@ -1573,7 +1571,17 @@ function prompt!(term, prompt, s = init_state(term, prompt)) activate(prompt, s, term) while true map = keymap(s, prompt) - state = match_input(map, s)(s, keymap_data(s, prompt)) + fcn = match_input(map, s) + # errors in keymaps shouldn't cause the REPL to fail, so wrap in a + # try/catch block + local state + try + state = fcn(s, keymap_data(s, prompt)) + catch e + warn("Caught an exception in the keymap:") + warn(e) + state = :done + end if state == :abort stop_reading(term) return buffer(s), false, false