From 94d13ef89958cbc9dfe3367236b93b8da3a476e4 Mon Sep 17 00:00:00 2001 From: Nicolas Barray Date: Wed, 10 Jun 2015 11:43:39 +0200 Subject: [PATCH] shortcut: explicit exception message In the function remove_shortcut, if the action failed, it used to throw an 'implementation oriented' exception message: > throws('try to delete non-leaf') This is not a good message for the user who wants to mess with the shortcuts. The solution is to leave this 'implementation oriented' exception message and add a try-catch bloc above that catches this message and throws a new, frendliest, exception message. I came up with this: > throws('try to remove non-existing shortcut') * notebook/static/base/js/keyboard.js: (remove_shortcut) add try-catch. Signed-off-by: Nicolas Barray --- notebook/static/base/js/keyboard.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/notebook/static/base/js/keyboard.js b/notebook/static/base/js/keyboard.js index f2e41f0e1..d444f15f9 100644 --- a/notebook/static/base/js/keyboard.js +++ b/notebook/static/base/js/keyboard.js @@ -385,10 +385,19 @@ define([ if( typeof(shortcut) === 'string'){ shortcut = shortcut.split(','); } - this._remove_leaf(shortcut, this._shortcuts); - if (!suppress_help_update) { + /* + * The shortcut error should be explicit here, because it will be + * seen by users. + */ + try + { + this._remove_leaf(shortcut, this._shortcuts); + if (!suppress_help_update) { // update the keyboard shortcuts notebook help this.events.trigger('rebuild.QuickHelp'); + } + } catch (ex) { + throw ('try to remove non-existing shortcut'); } };