bbcmicrobit / PythonEditor

A MicroPython editor for the BBC micro:bit that works with browsers.
https://python.microbit.org/
MIT License
196 stars 130 forks source link

WebUSB error "Cannot read property 'replace' of undefined" #268

Closed microbit-sam closed 4 years ago

microbit-sam commented 4 years ago

Check that err.message exists before using it


May not be necessary, updated translation handling can probably remove the possibility of this happening

microbit-carlos commented 4 years ago

Have you been able to replicate the original issue? Or do you know the type of the object that gets to this point? Basically we are getting something that is not an Error object, and I think we need to understand what that is and why that happens, as this might be a symptom of a different problem.

microbit-sam commented 4 years ago

No I've not managed to discover that yet, almost all of the calls to webusbErrorHandler are from .catch() events so should have them

The only call that isn't from a catch() is

  var error = {"name": "device-disconnected", "message": config["translate"]["webusb"]["err"]["device-disconnected"]};
        webusbErrorHandler(error);

I'm checking translations now, but I would have thought message would still have been defined even if there was a missing translation

microbit-carlos commented 4 years ago

That sounds like a good candidate as the original issue was found when the editor was in Spanish.

microbit-sam commented 4 years ago

If so, shall I move the check to:

  var error = {"name": "device-disconnected", "message": (config["translate"]["webusb"]["err"]["device-disconnected"] ? config["translate"]["webusb"]["err"]["device-disconnected"] : "missing-translation" };
        webusbErrorHandler(error);
microbit-sam commented 4 years ago

Actually I've just realised, the metrics will have seperate URLs for errors in different languages.. that's not ideal

microbit-carlos commented 4 years ago

I think we need a better way to deal with missing translations. Likely to create a "getter" that returns the english version if the string is not found.

microbit-sam commented 4 years ago

I think we need a better way to deal with missing translations. Likely to create a "getter" that returns the english version if the string is not found.

Yep that sounds like a good idea

microbit-carlos commented 4 years ago

Saw this error again while testing PR #270: image

So it looks like it's not related to the translations after all.

microbit-sam commented 4 years ago

Interesting, do you still have that window open? I think errors should be logged when webusbErrorHandler is called

microbit-sam commented 4 years ago

I've restructured webusbErrorHandler, and it feels better to me, but you may have other thoughts Carlos!