I have a web-page served by node.js. In the web-page is a loadTable which loads a csv file from disk. loadTable is async and the draw action is controlled by iLoadData. In the good callback, this is incremented and the next phase uses the data in the table. This all works fine. When the the file is missing it goes into the ‘bad’ callback, but then crashes. The bad callback sets iLoadData to zero and there’s no more action in draw, but it still crashes. How should I handle this error?
console.log("T Bad " + iLoadData);
iLoadData = 0;
if (iLoadData == 2)
table = loadTable(sFilename, 'csv', "", loadTableGood, loadTableBad);
if (iLoadData == 3)
// read out of the table.
T Bad 2 [sketch.js:408:10](http://192.168.1.14:8083/sketch.js)
Uncaught (in promise) Error: [object Object]
promise callback*</v.prototype.httpDo http://192.168.1.14:8083/p5.min.js:3
@GoToLoop My notifications list is showing you’ve replied (? pencil) but I can’t see the reply and the topic summary shows no replies.
The icon means a post got edited. In your case I’ve merely changed its forum category.
However as long as iLoadData is still
2 loadTable() will keep being invoked each draw() iteration!
It takes a while until iLoadData is either increased by
1 or reset back to
It’d be nice if you had an actual runnable sketch demoing that for us to test it.
Anyways I’ve ended up coding 1 here:
In my version it logs 2 errors on the browser’s console when it attempts to load the non-existing filename “ab.csv”:
- GET https://bl.ocks.org/GoSubRoutine/raw/823e9f8b008b7481b11d5f4f12a80839/ab.csv 404
- Uncaught (in promise) Error: [object ReadableStream] at p5:3:607922
However it doesn’t crash the sketch, as it goes on loading the correct filename “xy.csv” after that 1st fail and the sketch’s canvas keeps on changing its background() color.
@gotoloop thanks for all that.
- you moved it, fine.
- the problem with the phases in the code wasn’t quite the same as I posted. (At the time I couldn’t think how to extract a minimum working example from my sprawling development.) There was a problem with testing iLoadData and I was sometimes reading the table before it was ready. I thought the ‘uncaught’ was the problem but it has to be ignored.
Your example is interesting, several new-to-me useful things:
- Uint8Array.from - array construction.
- use strict - (= ‘option explicit’ in VB 20 years ago)
- console.info - coloured messages in the log.