Opened 5 years ago
Last modified 2 years ago
#19648 new enhancement
[patch] Show warning on invalid MapCSS validator rule parsing
Reported by: | skyper | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core | Version: | |
Keywords: | template_report rule validation mapcss class | Cc: |
Description
What steps will reproduce the problem?
- Have a typo in a validator mapcss rule file, like the missing
y
below:way[highway =~ /^(motorway|motorway_link|trunk|trunk_link)$/] { set MotorwayTrunk; } way.MotorwaTrunk[lanes][turn:lanes ][tag(lanes)!=eval(count(split("|", tag("turn:lanes"))))], way.MotorwaTrunk[lanes][change:lanes ][tag(lanes)!=eval(count(split("|", tag("change:lanes"))))], way.MotorwaTrunk[lanes][maxspeed:lanes ][tag(lanes)!=eval(count(split("|", tag("maxspeed:lanes"))))], way.MotorwaTrunk[lanes][minspeed:lanes ][tag(lanes)!=eval(count(split("|", tag("minspeed:lanes"))))], way.MotorwaTrunk[lanes][destination:lanes ][tag(lanes)!=eval(count(split("|", tag("destination:lanes"))))], way.MotorwaTrunk[lanes][destination:ref:lanes ][tag(lanes)!=eval(count(split("|", tag("destination:ref:lanes"))))], way.MotorwaTrunk[lanes][destination:symbol:lanes][tag(lanes)!=eval(count(split("|", tag("destination:symbol:lanes"))))] { throwWarning: tr("Different number of lanes in the keys {0} and {1}", "{1.key}", "{2.key}"); group: tr("suspicious tag combination"); }
- (Re-)Load file
What is the expected result?
A warning about an unknown class in use.
What happens instead?
No warning
Please provide any additional information below. Attach a screenshot if possible.
Some Information about existing but not use classes would be nice, too.
Relative:URL: ^/trunk Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b Last:Changed Date: 2020-08-06 21:47:58 +0200 (Thu, 06 Aug 2020) Revision:16851 Build-Date:2020-08-07 01:30:47 URL:https://josm.openstreetmap.de/svn/trunk
Attachments (1)
Change History (19)
comment:1 by , 3 years ago
Summary: | MapCSS Rule validation: Warn about unknown class. → Show warning on invalid MapCSS validator rule parsing |
---|
comment:2 by , 3 years ago
comment:3 by , 3 years ago
The issue is coming from the MapCSSParser.jj
file. I have a patch that makes JOSM print the messages but at the same time introduces some GUI exceptions (EDT violations).
comment:4 by , 3 years ago
Summary: | Show warning on invalid MapCSS validator rule parsing → [WIP patch] Show warning on invalid MapCSS validator rule parsing |
---|
-
src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
14 14 import java.util.Collections; 15 15 import java.util.List; 16 16 17 import javax.swing.JOptionPane; 18 17 19 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 20 import org.openstreetmap.josm.gui.MainApplication; 18 21 import org.openstreetmap.josm.gui.mappaint.Keyword; 19 22 import org.openstreetmap.josm.gui.mappaint.Range; 20 23 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; … … 78 81 this.idx = idx; 79 82 } 80 83 } 81 84 82 85 /** 83 86 * Constructor which initializes the parser with a certain lexical state. 84 87 * @param in input … … 1164 1167 1165 1168 Logging.error("Skipping to the next rule, because of an error:"); 1166 1169 Logging.error(e); 1170 1171 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), e.getMessage(), "MapCSS rule parsing error", JOptionPane.ERROR_MESSAGE); 1167 1172 if (sheet != null) { 1168 1173 sheet.logError(e); 1169 1174 }
The patch introduces some EDT violations, which needs to be solved first. If someone knows how to fix it, please do it.
by , 3 years ago
Attachment: | josm_19648.patch added |
---|
comment:6 by , 3 years ago
Summary: | [WIP patch] Show warning on invalid MapCSS validator rule parsing → [patch] Show warning on invalid MapCSS validator rule parsing |
---|
Thank you @GerdP! Now the EDT violations are gone. I think the patch is good enough, but please review it.
comment:7 by , 3 years ago
You can simplify that to GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(..));
like in MainLayerManager:
GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Trying to delete the layer with background upload. Please wait until the upload is finished."))); }
comment:9 by , 3 years ago
Looking at the release-notes.md, v7.0.5 "[added] support for Java7 language features". So I don't think Java 8 language features are supported.
follow-up: 12 comment:10 by , 3 years ago
Ah, sorry, I got carried away and forgot to check why. If you think it's useful please commit it. I only tried to help reg. the EDT stuff.
comment:11 by , 3 years ago
Sorry, I wasn't specific by writing JavaCC doesn't like lambdas, but as taylor.smock wrote, JavaCC supports Java up to version 7.
follow-up: 14 comment:12 by , 3 years ago
Replying to GerdP:
Ah, sorry, I got carried away and forgot to check why. If you think it's useful please commit it. I only tried to help reg. the EDT stuff.
I thought you had been looking at the patch. I just figured I'd look into it to see if one of the version updates for JavaCC had added Java 8 language feature support (I think I recently updated our version of JavaCC).
In that case, @gaben, what problem (exactly) are you trying to solve? The supplied patch does nothing to show a warning about a missing class. It just adds another method for informing a user that something might be wrong, and doesn't even trigger on the example mapcss.
Here is some broken mapcss for testing (i.e., what currently happens):
way[highway =~ /^(motorway|motorway_link|trunk|trunk_link)$/] { set MotorwayTrunk; } /* Should be broken */ way.MotorwaTrunk[lanes][destination:symbol:lanes][tag(lanes)!=eval(count(split("|", tag("destination:symbol:lanes"))))] { throwWarning: tr("Different number of lanes in the keys {0} and {1}", "{1.key}", "{2.key}"); group: tr("suspicious tag combination"); } /* Broken */ way[hhhh===dddd] {} way[highway=residential] { throwMessage("Not a valid thing");} way3 {}
You will notice that the Map Paint Styles
toggle dialog will show the paint style with an exclamation mark. Right-click -> Info
-> Errors
will then show the problems. If you look at the console output, you will see more output (from the Logging
calls).
So we need to throw an exception when we encounter a class that does not currently exist.
(Also, JOSM now has a validate
command line switch. Example usage: java -jar dist/josm-custom.jar validate --input test.mapcss
)
comment:13 by , 3 years ago
Good catch! I need to revisit what I've done and why, but I remember we worked together with @skyper on a different ticket, and the validator did not warn us about invalid MapCSS rules in runtime, hence the patch. I just ignored the example, probably.
follow-up: 15 comment:14 by , 3 years ago
Replying to taylor.smock:
In that case, @gaben, what problem (exactly) are you trying to solve?
If I remember correctly, there is a "hot reload" feature in JOSM, which allows rules reloading simply by saving the rule file. If there is an invalid rule, this feature will stop working silently until JOSM restart. With the patch, at least the user will know there is an issue and why isn't it working (detailed message printed).
comment:15 by , 3 years ago
Replying to gaben:
If I remember correctly, there is a "hot reload" feature in JOSM, which allows rules reloading simply by saving the rule file. If there is an invalid rule, this feature will stop working silently until JOSM restart. With the patch, at least the user will know there is an issue and why isn't it working (detailed message printed).
Yep, there is a hot reload feature. I haven't seen it stop working after an invalid rule though. If you have an example, we should probably fix that.
comment:16 by , 3 years ago
Yes, the auto reload does stop working once there is a syntax error (e.g. unexpected symbol
). Manually reloading will still work but for auto-reload you need to restart JOSM. (Do not know if it is the same with mappaint styles).
comment:17 by , 3 years ago
Looks like there is a difference between MapCSSTagChecker.java and MapPaintStyles.java.
This can probably be fixed by moving the FileWatcher#registerSource
call above the MapCSSTagChecker#addMapCss
call.
EDIT: Note that this appears to only be a problem on _first_ load of the validator.mapcss rule.
-
src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
diff --git a/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java b/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java index ef9c500e49..40e9b5f991 100644
a b public class MapCSSTagChecker extends Test.TagTest { 331 331 } else if (Logging.isDebugEnabled()) { 332 332 Logging.debug(tr("Adding {0} to tag checker", i)); 333 333 } 334 addMapCSS(i);335 334 if (Config.getPref().getBoolean("validator.auto_reload_local_rules", true) && source.isLocal()) { 336 335 FileWatcher.getDefaultInstance().registerSource(source); 337 336 } 337 addMapCSS(i); 338 338 } catch (IOException | IllegalStateException | IllegalArgumentException ex) { 339 339 Logging.warn(tr("Failed to add {0} to tag checker", i)); 340 340 Logging.log(Logging.LEVEL_WARN, ex);
comment:18 by , 2 years ago
Hm didn't check it but your change should solve the code break, while mine will notify if something is off.
While experimenting with a custom MapCSS rule, I noticed parsing of invalid rules silently fail on the GUI side. In case of error, the console prints detailed information. Add this or parts to a warning dialog to help diagnose the problem.