-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KeepRight] Use regex group capture to extract error details #5275
[KeepRight] Use regex group capture to extract error details #5275
Conversation
This focuses on converting error types I found on the map for testing (can confirm the code is working!) as well as the more problematic cases from the old code to show that this approach can handle them easily.
This adds a flag to the error schema to explicitly say whether to parse the description with regex or not. Prevents us from having to escape special characters in fixed strings and is a minor optimisation.
These aren't shown in the layer currently, but for future use this should work
I consider this PR now feature complete 😃 All error types now have details extracted via regex and as a bonus I've handled cases where arbitrary lists of IDs could be present so that they all become links. Locations with some of the more complicated errors: Some of the output messages on our end (in |
Thank you very much @SilentSpike for the great refactor. I've reviewed these changes and I am fine merging them so long as there aren't parsing conflicts between the templates and the KeepRight.at server responses. |
As discussed here, this PR improves the extraction of details from error descriptions by directly using regex group capture instead of splitting the strings and using a lot of logic to figure out what's what (effectively re-implementing the same group capture behaviour).
Advantages of this approach:
iD/modules/util/keepRight/keepRight_error.js
Lines 66 to 73 in 74e06d4
.test()/.match()
methods.\d+
shows that we expect a number whereas{$1}
didn't). This is a minor maintainability improvement.Side effect of this approach:
"IDs"
key to theerrorSchema.json
which provides an array of strings where the indices correspond to the regex groups (see here). This let's us explicitly tell the code which groups capture an ID and what type of ID they are ("n"/"w"/"r"
)."regex"
key to theerrorSchema.json
so that errors where the message is fixed aren't parsed for details at all (saves us having to escape any special regex characters and prevents needlessly matching a fixed string for many errors). However, it might actually make more sense to just remove these messages all together from the file since we don't need that data for anything.