Error on console

jh-changes
Shin'ya Ueoka 6 years ago
parent 6f4e327b6f
commit 4bd2084ba7
  1. 5
      src/background/controllers/command.js
  2. 11
      src/background/infrastructures/content-message-listener.js

@ -48,6 +48,10 @@ export default class CommandController {
let trimmed = line.trimStart(); let trimmed = line.trimStart();
let words = trimmed.split(/ +/); let words = trimmed.split(/ +/);
let name = words[0]; let name = words[0];
if (words[0].length === 0) {
return Promise.resolve();
}
let keywords = trimmed.slice(name.length).trimStart(); let keywords = trimmed.slice(name.length).trimStart();
switch (words[0]) { switch (words[0]) {
case 'o': case 'o':
@ -85,5 +89,6 @@ export default class CommandController {
case 'set': case 'set':
return this.commandIndicator.set(keywords); return this.commandIndicator.set(keywords);
} }
throw new Error(words[0] + ' command is not defined');
} }
} }

@ -18,12 +18,19 @@ export default class ContentMessageListener {
run() { run() {
browser.runtime.onMessage.addListener((message, sender) => { 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, { return browser.tabs.sendMessage(sender.tab.id, {
type: messages.CONSOLE_SHOW_ERROR, type: messages.CONSOLE_SHOW_ERROR,
text: e.message, text: e.message,
}); });
}); }
}); });
} }