diff --git a/CHANGELOG.md b/CHANGELOG.md index fe49e882..ef740c7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +- **A damaged hook point catalogue file says which one, and the Car Report says map-car didn't + run** (#470). On a 2022 Ioniq 5 (NEEV.USA, 260903) one of `maps/catalogue/*.json` was all zero + bytes after the install had checked it, so every `map-car` stopped with "JSON: unexpected + character '\u0000' at offset 0", naming no file, and the report summed it up as "null hook + point(s) found". The error now names the file and says to install HMG-API again; the report, + its Markdown and the issue link say "didn't run, ". Tested off-car + (`core/runtime/local-map-test.sh`, a new case that fails before this change). - **The Car Report no longer carries the unit's mobile-data address.** Its iptables dump only had MAC addresses taken out, and Android's own chains (`st_mangle_EXEMPT`) hold the unit's current mobile-data address and its carrier's servers. The rules are now scrubbed like the diff --git a/core/runtime/java/hmgapi/engine/MapProbe.java b/core/runtime/java/hmgapi/engine/MapProbe.java index 1667e524..ff0e9746 100644 --- a/core/runtime/java/hmgapi/engine/MapProbe.java +++ b/core/runtime/java/hmgapi/engine/MapProbe.java @@ -89,7 +89,18 @@ static Set catalogueStrings(File dir) throws Exception { Set out = new java.util.HashSet(); File[] cats = dir.listFiles(); if (cats == null) return out; - for (File f : cats) if (f.getName().endsWith(".json")) collectStrings(Json.parse(Engine.read(f)), out); + for (File f : cats) { + if (!f.getName().endsWith(".json")) continue; + Object o; + try { + o = Json.parse(Engine.read(f)); + } catch (IllegalArgumentException x) { // a file the install checked, damaged since (#470: all zero bytes) + // the advice first: the Car Report's summary keeps only the start + throw new IllegalArgumentException("a hook point catalogue file is damaged, install HMG-API again to put it back: " + + f.getPath() + " (" + x.getMessage() + ")", x); + } + collectStrings(o, out); + } return out; } diff --git a/core/runtime/java/hmgapi/engine/Report.java b/core/runtime/java/hmgapi/engine/Report.java index dc764147..8a271ecd 100644 --- a/core/runtime/java/hmgapi/engine/Report.java +++ b/core/runtime/java/hmgapi/engine/Report.java @@ -171,8 +171,8 @@ static int run(Engine e, boolean usb) throws Exception { e.out.add("report: " + name); e.out.add("car: " + carName(unit) + " " + unit.get("product")); e.out.add(map.describe()); - e.out.add("map-car: " + pj.get("found") + " hook point(s) found, " + ((Map) pj.get("not_found") == null ? 0 - : ((Map) pj.get("not_found")).size()) + " not found"); + e.out.add("map-car: " + (mapCarError(pj) != null ? mapCarError(pj) : pj.get("found") + " hook point(s) found, " + + ((Map) pj.get("not_found") == null ? 0 : ((Map) pj.get("not_found")).size()) + " not found")); String dis = disagreement(pj); if (dis != null) e.out.add("check the map: " + dis); e.out.add("saved: " + dir.getPath() + "/" + name + ".json"); @@ -280,8 +280,8 @@ static String markdown(Map r, String name) { .append(Boolean.TRUE.equals(unit.get("wifi_chip")) ? "yes" : "no").append("\n"); s.append("- ").append(map.get("summary")).append("\n"); Map nf = (Map) pj.get("not_found"); - s.append("- Mapped from this car's files: ").append(pj.get("found")).append(" points found, ") - .append(nf == null ? 0 : nf.size()).append(" not found\n"); + s.append("- Mapped from this car's files: ").append(mapCarError(pj) != null ? mapCarError(pj) + : pj.get("found") + " points found, " + (nf == null ? 0 : nf.size()) + " not found").append("\n"); String dis = disagreement(pj); if (dis != null) s.append("- **Check the map:** ").append(dis).append("\n"); s.append("\n"); @@ -353,6 +353,18 @@ static String disagreement(Map pj) { return s.toString(); } + /** + * Why map-car couldn't run, in a line (short: it goes in the issue link too), or null if it ran. + * Without this the summaries said "null points found" (#470). + */ + static String mapCarError(Map pj) { + Object err = pj.get("error"); + if (err == null) return null; + // without the exception's class name ("java.lang.IllegalArgumentException: "), which takes room and says nothing + String m = String.valueOf(err).replaceFirst("^[\\w.$]+(Exception|Error): ", ""); + return "didn't run, " + (m.length() > 160 ? m.substring(0, 157) + "..." : m); + } + /** A link that opens a new GitHub issue with the summary filled in (short: it goes in a QR code). */ @SuppressWarnings("unchecked") static String issueUrl(Map r, String name) throws Exception { @@ -363,7 +375,8 @@ static String issueUrl(Map r, String name) throws Exception { String body = "Product: " + unit.get("product") + "\nHMG-API: " + r.get("hmgapi") + (r.get("build") != null ? "\nBuild: " + r.get("build") : "") + "\nMap: " + map.get("status") + (Boolean.TRUE.equals(map.get("hooks_on")) ? " (hooks on)" : " (hooks off)") - + "\nFound on this car: " + pj.get("found") + " points, " + (nf == null ? 0 : nf.size()) + " not found" + + "\nFound on this car: " + (mapCarError(pj) != null ? mapCarError(pj) + : pj.get("found") + " points, " + (nf == null ? 0 : nf.size()) + " not found") + (r.get("network") instanceof Map && ((Map) r.get("network")).get("summary") != null ? "\nNetwork: " + ((Map) r.get("network")).get("summary") : "") + "\n\nPlease attach " + name + ".json (USB stick: HMG-API reports; adb: adb pull /data/hmgapi/public/reports/)."; diff --git a/core/runtime/local-map-test.sh b/core/runtime/local-map-test.sh index f88f1812..027e46f0 100644 --- a/core/runtime/local-map-test.sh +++ b/core/runtime/local-map-test.sh @@ -48,6 +48,19 @@ REP=$(ls $D/public/reports/*.json 2>/dev/null | head -1) [ -n "$REP" ] && check "the Car Report lists them (for a maintainer to make official)" '["test.a.flag", "test.a.later"]' \ "$(python3 -c 'import json,sys; print(json.dumps(json.load(open(sys.argv[1]))["map"]["mapped_here"]))' "$REP")" +# a catalogue file damaged on the unit (#470: all zero bytes): map-car names it and says how to put +# it back, and the Car Report says map-car didn't run (it said "null hook point(s) found") +mkdir -p $D/maps/catalogue; head -c 64 /dev/zero > $D/maps/catalogue/test.json +eng map-car --local +has "a damaged catalogue file: map-car says how to put it back" "is damaged, install HMG-API again to put it back" "$out" +has "... and names it" "catalogue/test.json (JSON: " "$out" +rm -f $D/public/reports/*; eng report +has "... the report says map-car didn't run, and what to do" "map-car: didn't run, a hook point catalogue file is damaged, install HMG-API again to put it back: " "$out" +hasnt "... not \"null\" points" "null hook point" "$out" +hasnt "... without the exception's class name" "IllegalArgumentException" "$out" +has "... the issue link too" "Found+on+this+car%3A+didn%27t+run%2C+a+hook+point+catalogue+file+is+damaged%2C+install+HMG-API+again" "$out" +rm -r $D/maps/catalogue $D/public/reports + mkdir -p $D/mods/watch $D/mods/change printf '{"id": "watch", "name": "W", "version": "1.0.0", "hmgapi": ">=1.0.0", "hooks": {"jar": "h.jar", "entry": "h.H", "points": {"test.a.flag": "observe"}}}\n' > $D/mods/watch/mod.json printf '{"id": "change", "name": "C", "version": "1.0.0", "hmgapi": ">=1.0.0", "hooks": {"jar": "h.jar", "entry": "h.H", "points": {"test.a.later": "change"}}}\n' > $D/mods/change/mod.json