Modify

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#18397 closed enhancement (fixed)

[PATCH] Provide more helpful error message when loading an invalid gpx file

Reported by: GerdP Owned by: team
Priority: normal Milestone: 19.12
Component: Core Version:
Keywords: template_report gpx Cc: Bjoeni

Description

What steps will reproduce the problem?

  1. Try to load attached gpx file (I removed most of the points, problem is in the header)

What is the expected result?

track is displayed

What happens instead?

popup "Could not read gpx file x.gpx" Error is: Parsing data for layer x.gpx failed.

Please provide any additional information below. Attach a screenshot if possible.

I have a lot of files which show this error, other tools can load them.

URL:https://josm.openstreetmap.de/svn/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2019-12-01 23:10:15 +0100 (Sun, 01 Dec 2019)
Build-Date:2019-12-02 02:30:57
Revision:15553
Relative:URL: ^/trunk

Identification: JOSM/1.5 (15553 en) Windows 10 64-Bit
OS Build number: Windows 10 Home 1903 (18362)
Memory Usage: 715 MB / 4551 MB (381 MB allocated, but free)
Java version: 1.8.0_221-b11, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM
Screen: \Display0 1920x1080
Maximum Screen Size: 1920x1080

Plugins:
+ OpeningHoursEditor (35242)
+ apache-commons (35092)
+ buildings_tools (35171)
+ continuosDownload (82)
+ ejml (35122)
+ geotools (35169)
+ jaxb (35014)
+ jts (35122)
+ merge-overlap (35072)
+ o5m (34908)
+ opendata (35179)
+ pbf (35033)
+ poly (34991)
+ reverter (35226)
+ undelete (34977)
+ utilsplugin2 (35238)

Last errors/warnings:
- W: No configuration settings found.  Using hardcoded default values for all pools.
- W: Region [TMS_BLOCK_v2] Resetting cache
- E: org.xml.sax.SAXParseException: The prefix "gpxx" for element "gpxx:TrackExtension" is not bound.
- E: java.io.IOException: Parsing data for layer 'x.gpx' failed. Cause: org.xml.sax.SAXParseException: The prefix "gpxx" for element "gpxx:TrackExtension" is not bound.
- E: Error - <html>Could not read file 'x.gpx'.<br>Error is:<br>Parsing data for layer 'x.gpx' failed</html>

Attachments (2)

x.gpx (1.7 KB ) - added by GerdP 4 years ago.
18397.patch (2.2 KB ) - added by Bjoeni 4 years ago.

Download all attachments as: .zip

Change History (15)

by GerdP, 4 years ago

Attachment: x.gpx added

comment:1 by GerdP, 4 years ago

Cc: Bjoeni added

comment:2 by Bjoeni, 4 years ago

The attached file violates the XML standard, JOSM (or rather SAX) was never able to read that (fails in 19.10-15492 as well).
The problem is the "Gpx Editor" here, the "gpxx" prefix has to be bound to the Garmin namespace like this xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3".

I'm not even sure if SAX allows parsing incorrect XML documents at all.

comment:3 by GerdP, 4 years ago

I agree that I got the same problems before. I just thought you might know a solution ;)

comment:4 by Don-vip, 4 years ago

Keywords: garmin gpx added
Resolution: invalid
Status: newclosed
Summary: Can't load a gpx fileCan't load an invalid Garmin gpx file

Simply fix the files or report the problem to Garmin.

comment:5 by Bjoeni, 4 years ago

Agreed (although not Garmin but some 3rd party "GPX Editor").

But I'd suggest passing on the error message from SAX and also displaying the creating software and line numbers for thrown errors (so not just for the warnings).
Because the current message

Could not read file "x.gpx".
Error is:
Parsing data for layer "x.gpx" failed.

isn't exactly helpful. The following patch would instead display the following:

Could not read file "x.gpx".
Error is:
The prefix "gpxx" for element "gpxx:TrackExtension" is not bound (at line 13, column 28).
The file was created by "GPX Editor 1.6.11.1624".
  • src/org/openstreetmap/josm/gui/io/importexport/GpxImporter.java

     
    112112            addLayers(loadLayers(r.getGpxData(), parsedProperly, fileName, tr("Markers from {0}", fileName)));
    113113        } catch (SAXException e) {
    114114            Logging.error(e);
    115             throw new IOException(tr("Parsing data for layer ''{0}'' failed", fileName), e);
     115            throw new IOException(e.getLocalizedMessage(), e);
    116116        }
    117117    }
    118118
  • src/org/openstreetmap/josm/io/GpxReader.java

     
    644644        } catch (SAXException e) {
    645645            if (tryToFinish) {
    646646                parser.tryToFinish();
    647                 if (parser.data.isEmpty())
    648                     throw e;
    649                 String message = e.getMessage();
     647                String message = e.getLocalizedMessage();
    650648                if (e instanceof SAXParseException) {
     649                    boolean dot = message.lastIndexOf('.') == message.length() - 1;
     650                    if (dot)
     651                        message = message.substring(0, message.length() - 1);
    651652                    SAXParseException spe = (SAXParseException) e;
    652653                    message += ' ' + tr("(at line {0}, column {1})", spe.getLineNumber(), spe.getColumnNumber());
     654                    if (dot)
     655                        message += '.';
    653656                }
    654                 Logging.warn(message);
     657                if (parser.data.creator != null && !parser.data.creator.trim().isEmpty()) {
     658                    message += "\n" + tr("The file was created by \"{0}\".", parser.data.creator);
     659                }
     660                SAXException ex = new SAXException(message, e);
     661                if (parser.data.isEmpty())
     662                    throw ex;
     663                Logging.warn(ex);
    655664                return false;
    656665            } else
    657666                throw e;

comment:6 by Don-vip, 4 years ago

Keywords: garmin removed
Milestone: 19.12
Resolution: invalid
Status: closedreopened
Summary: Can't load an invalid Garmin gpx file[PATCH] Provide more helpful error message when loading an invalid gpx file
Type: defectenhancement

comment:7 by GerdP, 4 years ago

@Bjoeni I failed to apply these patches. Not sure why.

comment:8 by Bjoeni, 4 years ago

Works perfectly fine for me. I just changed my OS language and the diff said "Arbeitskopie" instead of "working copy" but that should be completely irrelevant to svn.
I attached another patch (updated + english), maybe that works.

by Bjoeni, 4 years ago

Attachment: 18397.patch added

comment:9 by GerdP, 4 years ago

Yes, that works for me. Maybe problem is the upper case in [Rr]evision

comment:10 by Bjoeni, 4 years ago

Well I changed it back to English, applied the German patch and it worked, so I really don't know what happened. But whatever, glad it works now.

comment:11 by GerdP, 4 years ago

Just played with it. When I remove "(Arbeitskopie)" it works.
svn --version says

svn, version 1.12.2 (r1863366)
   compiled Aug  4 2019, 18:52:55 on x86-microsoft-windows

I'll try a newer version later.

comment:12 by GerdP, 4 years ago

Resolution: fixed
Status: reopenedclosed

In 15593/josm:

fix #18397: Provide more helpful error message when loading an invalid gpx file
patch by Bjoeni

in reply to:  7 comment:13 by Bjoeni, 3 years ago

Replying to GerdP:

@Bjoeni I failed to apply these patches. Not sure why.

Just in case you have a similar problem in the future:

I think I figured out what went wrong back then as I just had a similar issue. SVN fails to apply UTF-16 encoded patches (every second byte is 00 in that case). That's probably why it worked after you modified and saved it in a text editor.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.