bugfix(@embark/console): catch exceptions from a badly regex caused by a suggestion contains ( or ) at the end of the string

This commit is contained in:
Iuri Matias 2018-11-29 15:43:40 -05:00
parent 27babf0187
commit 00be382be7

View File

@ -75,7 +75,11 @@ export default class Suggestions {
suggestions.push({value: "web3", command_type: "javascript object", description: "instantiated web3.js object configured to the current environment"});
suggestions.push({value: "EmbarkJS", command_type: "javascript object", description: "EmbarkJS static functions for Storage, Messages, Names, etc."});
if (cmd.indexOf(".") > 0) {
if (cmd.indexOf(".") <= 0) {
return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original));
}
try {
const toRemove: string = "." + cmd.split(".").reverse()[0];
const cmdToSearch: string = cmd.replace((new RegExp(toRemove + "$")), "");
return this.events.request("runcode:eval", "Object.keys(" + cmdToSearch + ")", (err: any, result: any) => {
@ -90,6 +94,7 @@ export default class Suggestions {
return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original));
}, false, true);
} catch (e) {
}
return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original));