Skip to content
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

Error Handling #29

Open
stelldogg opened this issue Jun 4, 2021 · 3 comments
Open

Error Handling #29

stelldogg opened this issue Jun 4, 2021 · 3 comments
Assignees
Labels

Comments

@stelldogg
Copy link

stelldogg commented Jun 4, 2021

I'm constantly fighting this thing to take the right format file. I have a local file that I have parsed sucessfully before, but when trying to port all of my code to server and run:

let gpx = new gpxParser();
fs.readFile(gpxRecord.file, { encoding: "utf-8" }, function (error, data) {
  parser.parseString(data, function (err, res) {
    if (err) console.log(err);

    console.log(res.gpx);
    gpx.parse(res.gpx);
    console.log("Found " + gpx.tracks.length + " tracks");
  });
});

The code above never shows any tracks.

Any tips on locating errors when parsing this thing?

@Luuka Luuka self-assigned this Jun 7, 2021
@Luuka Luuka added the question label Jun 7, 2021
@Luuka
Copy link
Owner

Luuka commented Jun 7, 2021

Hello,

I don't know from where come the parser.parseString function but you shouldn't need it.
fs.readFile already return a string that should be directly parsed.

let gpx = new gpxParser();
fs.readFile(<YourFilePath>, { encoding: "utf-8" }, function (error, data) {
    gpx.parse(data);
    console.log("Found " + gpx.tracks.length + " tracks");
});

@stelldogg
Copy link
Author

Hi Luuka - I did eventually get it to work. Thanks for the response. I was asking more in terms of some info regarding the success of the call to gxp.parse(<data>).

@sutarmin
Copy link

sutarmin commented Dec 2, 2021

hey, @Luuka thanks for your lib! I have the same question: is there a way to determine whether parsing has finished successfully?
I noticed that the library just stops parsing when an unexpected tag happens and I didn't find a way of ensuring that the whole file was parsed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants