wohali commented on a change in pull request #1137: Validate regex on client
side.
URL: https://github.com/apache/couchdb-fauxton/pull/1137#discussion_r225258275
##########
File path: app/addons/documents/mango/components/MangoQueryEditor.js
##########
@@ -130,16 +131,54 @@ export default class MangoQueryEditor extends Component {
notifyOnQueryError() {
if (this.editorHasErrors()) {
FauxtonAPI.addNotification({
- msg: 'Please fix the Javascript errors and try again.',
+ msg: 'Please fix the JSON errors and try again.',
type: 'error',
clear: true
});
return true;
}
+
return false;
}
+ getJsonIfValid(json) {
+ try {
+ return JSON.parse(json);
+ } catch (e) {
+ FauxtonAPI.addNotification({
+ msg: 'Please fix the JSON errors and try again. Error: ' + e.message,
+ type: 'error',
+ clear: true
+ });
+ }
+ }
+
+ isRegexValid(selector = {}) {
+ const regexes = Helper.getSelectorRegexes(selector);
+ const errors = _.reduce(regexes, (acc, val) => {
+ try {
+ new RegExp(val);
Review comment:
@willholley @popojargo Right, the idea is that we need much better error
messages from Couch when a regex fails, and that many ultra-simple syntax
errors can be caught in client-side directly - for instance having sufficient
`/` count.
I appreciate the "impedence mismatch" between Erlang re and JavaScript
regexes being a concern. The ultimate goal is to enable people working in
Fauxton to find their errors more readily, and for the editor provide some sort
of syntax highlighting or in-line guide to what might be wrong vs. having to
read a likely truncated, obscure error message in the warning bar at the top
after submission.
Suggestions are very welcome here :) Personally, I'm reacting to requests
for improvement from IRC/Slack support for basic things like regex syntax
highlighting and error parsing, which seem like low hanging fruit, even if we
take a naive approach. What do you think?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services