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: Improved comments Created June 8, 2015, 11:59 a.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
« no previous file with comments | « lib/filterValidation.js ('k') | qunit/tests/filterValidation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « lib/filterValidation.js ('k') | qunit/tests/filterValidation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld