Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: options.js

Issue 5655474749833216: Issue 2658 - Got rid of try..catch for filter validation (Closed)
Patch Set: Created June 7, 2015, 2:47 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -471,20 +471,16 @@
event.preventDefault();
var element = document.getElementById("newFilter");
- var filter;
+ var result = parseFilter(element.value);
- try
+ if (result.error)
{
- filter = parseFilter(element.value);
- }
- catch (error)
- {
- alert(error);
+ alert(result.error);
return;
}
- if (filter)
- FilterStorage.addFilter(filter);
+ if (result.filter)
+ FilterStorage.addFilter(result.filter);
element.value = "";
}
@@ -541,22 +537,18 @@
function importRawFiltersText()
{
var text = document.getElementById("rawFiltersText").value;
+ var result = parseFilters(text, true);
- var add;
- try
+ if (result.error)
{
- add = parseFilters(text, true);
- }
- catch (error)
- {
- alert(error);
+ alert(result.error);
return;
}
var seenFilter = Object.create(null);
- for (var i = 0; i < add.length; i++)
+ for (var i = 0; i < result.filters.length; i++)
{
- var filter = add[i];
+ var filter = result.filters[i];
FilterStorage.addFilter(filter);
seenFilter[filter.text] = null;
}

Powered by Google App Engine
This is Rietveld