aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-28 19:41:07 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-28 19:43:35 +0900
commit4bd2084ba7b23327c26a2d8b24dc4169c14bfa17 (patch)
tree6ac3f5ac5126e1a07c958549c782aedd586c6534
parent6f4e327b6f91aa687b373463d8bc284ffaceba53 (diff)
Error on console
-rw-r--r--src/background/controllers/command.js5
-rw-r--r--src/background/infrastructures/content-message-listener.js11
2 files changed, 14 insertions, 2 deletions
diff --git a/src/background/controllers/command.js b/src/background/controllers/command.js
index 41057e0..befab42 100644
--- a/src/background/controllers/command.js
+++ b/src/background/controllers/command.js
@@ -48,6 +48,10 @@ export default class CommandController {
let trimmed = line.trimStart();
let words = trimmed.split(/ +/);
let name = words[0];
+ if (words[0].length === 0) {
+ return Promise.resolve();
+ }
+
let keywords = trimmed.slice(name.length).trimStart();
switch (words[0]) {
case 'o':
@@ -85,5 +89,6 @@ export default class CommandController {
case 'set':
return this.commandIndicator.set(keywords);
}
+ throw new Error(words[0] + ' command is not defined');
}
}
diff --git a/src/background/infrastructures/content-message-listener.js b/src/background/infrastructures/content-message-listener.js
index 2fa5f54..58716fb 100644
--- a/src/background/infrastructures/content-message-listener.js
+++ b/src/background/infrastructures/content-message-listener.js
@@ -18,12 +18,19 @@ export default class ContentMessageListener {
run() {
browser.runtime.onMessage.addListener((message, sender) => {
- return this.onMessage(message, sender).catch((e) => {
+ try {
+ return this.onMessage(message, sender).catch((e) => {
+ return browser.tabs.sendMessage(sender.tab.id, {
+ type: messages.CONSOLE_SHOW_ERROR,
+ text: e.message,
+ });
+ });
+ } catch (e) {
return browser.tabs.sendMessage(sender.tab.id, {
type: messages.CONSOLE_SHOW_ERROR,
text: e.message,
});
- });
+ }
});
}