Commit 50e67ad1 authored by Thomas Greiner's avatar Thomas Greiner

Issue 7273 - Resolve filter parsing error messages in UI

parent b0e48afa
Pipeline #47033060 passed with stages
in 9 minutes and 9 seconds
......@@ -25,3 +25,13 @@ function getDocLink(link, callback)
link
}, callback);
}
function getErrorMessage(error)
{
const message = browser.i18n.getMessage(error.reason, error.selector);
if (error.lineno)
return browser.i18n.getMessage("line", [error.lineno.toString(), message]);
return message;
}
......@@ -24,6 +24,7 @@
<script src="polyfill.js"></script>
<script src="ext/common.js"></script>
<script src="ext/content.js"></script>
<script src="common.js"></script>
<script src="i18n.js"></script>
<script src="composer.js"></script>
</head>
......
......@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* globals getErrorMessage */
"use strict";
let targetPageId = null;
......@@ -42,7 +44,10 @@ function addFilters()
errors =>
{
if (errors.length > 0)
{
errors = errors.map(getErrorMessage);
alert(errors.join("\n"));
}
else
closeDialog(true);
});
......
......@@ -33,6 +33,9 @@ Naming convention: `subject` `.` `action` (e.g. `filters.get`)
- [importRaw](#filtersimportraw)
- [listen](#filterslisten)
- [remove](#filtersremove)
- [replace](#filtersreplace)
- [toggle](#filterstoggle)
- [validate](#filtersvalidate)
- prefs
- [get](#prefsget)
- [listen](#prefslisten)
......@@ -126,7 +129,7 @@ If filter includes `showPageOptions`:
**Response**
**string[]** errors
**[FilterError](#filtererror)[]** errors
#### filters.blocked
......@@ -160,7 +163,7 @@ If filter includes `showPageOptions`:
**Response**
**string[]** errors
**[FilterError](#filtererror)[]** errors
#### filters.listen
......@@ -181,6 +184,28 @@ See [`filterNotifier`][filternotifier].
- **string** [subscriptionUrl]
- **string** text
#### filters.replace
- **string** new
- **string** old
**Response**
**[FilterError](#filtererror)[]** errors
#### filters.toggle
- **string** text
- **boolean** disabled
#### filters.validate
- **string** text
**Response**
**[FilterError](#filtererror)[]** errors
---
### prefs
......@@ -302,6 +327,13 @@ See [`filterNotifier`][filternotifier].
- **string** text
### FilterError
- **number** [lineno]
- **string** [reason]
- **string** [selector]
- **string** type
### Subscription
- **boolean** disabled
......
......@@ -15,7 +15,7 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* globals getDocLink */
/* globals getDocLink getErrorMessage */
"use strict";
......@@ -579,7 +579,10 @@ function sendMessageHandleErrors(message, onSuccess)
browser.runtime.sendMessage(message, (errors) =>
{
if (errors.length > 0)
{
errors = errors.map(getErrorMessage);
alert(errors.join("\n"));
}
else if (onSuccess)
onSuccess();
});
......
......@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* globals getErrorMessage */
"use strict";
require("./io-checkbox");
......@@ -564,7 +566,7 @@ const createImageFor = (weakMap, filter) =>
const image = new Image();
image.src = `skin/icons/${isIssue ? "error" : "alert"}.svg`;
if (isIssue)
image.title = filter.reason;
image.title = getErrorMessage(filter.reason);
weakMap.set(filter, image);
return image;
};
......
......@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/* globals getErrorMessage */
"use strict";
const IOElement = require("./io-element");
......@@ -108,7 +110,7 @@ class IOFilterTable extends IOElement
delete node.dataset.filter;
bind(node)`${
errors ?
errors.join("\n") :
errors.map(getErrorMessage).join("\n") :
{i18n: "filter_action_failed"}
}`;
}
......
......@@ -75,6 +75,16 @@
return obj;
}
function convertError(error)
{
const obj = convertObject(["lineno", "reason", "selector"], error);
if (!obj.reason)
{
obj.reason = error.type.replace(/-/g, "_");
}
return obj;
}
// pollute a converted filter object with `slow` detail
// there are 3 kind of slow filters
// 1. filter instanceof RegExpFilter && defaultMatcher.isSlowFilter(filter)
......@@ -296,7 +306,7 @@
for (const error of result.errors)
{
if (error.type != "unexpected-filter-list-header")
errors.push(error.toString());
errors.push(convertError(error));
}
if (errors.length > 0)
......@@ -351,12 +361,7 @@
port.on("filters.validate", (message, sender) =>
{
const result = require("filterValidation").parseFilters(message.text);
const errors = [];
for (const error of result.errors)
{
errors.push(error.toString());
}
return errors;
return result.errors.map(convertError);
});
port.on("prefs.get", (message, sender) =>
......@@ -516,7 +521,7 @@
const result = require("filterValidation").parseFilter(message.text);
const errors = [];
if (result.error)
errors.push(result.error.toString());
errors.push(convertError(result.error));
else if (result.filter)
FilterStorage.addFilter(result.filter);
......
......@@ -26,11 +26,16 @@
}
},
"line": {
"description": "Prepended to error messages to indicate the line number (e.g. \"Line 42: Some error on this line\")",
"message": "Line $number$",
"description": "Error message with line number indicator",
"message": "Line $number$: $message$",
"placeholders": {
"message": {
"content": "$2",
"example": "Some error on this line"
},
"number": {
"content": "$1"
"content": "$1",
"example": "42"
}
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment