Catching errors in Espruino Modules (SX127x) #7417
Replies: 1 comment
-
Posted at 2020-09-26 by Robin Sat 2020.09.26 Hello @user114366, I haven't tested this and am not at my development PC but one item of clarification. Is the above snippet being uploaded from the R-Hand editor side of the WebIDE? link from: > ref: 'Uncatched Error:' Should this be taken literally as actual error text? The module source: (link from third line: http://www.espruino.com/SX127x) Posted at 2020-09-27 by rj Hi Robin 🙂! It's uploaded from the right-hand side, then uploaded to Flash using the "Send to Espruino" button in the IDE. I have boiled down the code to this (right-hand side):
No, the error is always as shown below:
I don't quite understand what you are suggesting 🙂. Which properties could I test against Thanks for taking the time to help 😁! Posted at 2020-09-27 by Robin Sun 2020.09.27 Good Afternoon @user114366! Thank you for clarifying the literal 'uncaught' exception error, the full snippet and the exact error as shown. Still not at a development PC to test, so going from memory here and wanted to respond timely as I know your time is limited to the weekends.
I had hoped that the review of the var's value and use of Opening module SX127x.js I searched for the error that is displayed.
> 'why throw an error if you are prevented from handling it' Agreed, and as the statement
led me to believe it is comm that is causing the error to be thrown, and the #1 snippet is what I actually do when loading an unknown module. It is quite possible that as we have a module SX.init() called from within E.on() own init function, and there may be some reason the bubble up error is not able to be trapped. I perform my test circa 1V95 in it's own function outside of init().
My conception was to test the value of Another trick I use is to test the var value of assigned constants in the called module. In this case:
Should the module not be fetched, var 'REG' won't exist in the namespace and may be checked using dump(); and will contain the module constant data, and not 'undefined' when Espruino successfully loads/parses the module.
I'm with you here, but in defense of the author, from line 3 within: In bold text: 'however it is extremely beta' Posted at 2020-09-27 by @MaBecker you can use this statement to include the module into you code https://www.espruino.com/Reference#l_Modules_addCached and than some console.log() statements to nail down what’s going wrong. Posted at 2020-09-27 by AkosLukacs You won't be able to catch that exception, since it's called in a setTimeout Posted at 2020-09-27 by rj Hi AkosLukacs,
Although regrettable, thanks for confirming that--that basically settles it 😕👍 . Posted at 2020-09-27 by rj Hi MaBe, While AkosLukacs has confirmed that I will never be able to catch the exception, I'll see that come in handy next time I'm debugging Espruino modules--thanks 👍. Posted at 2020-09-27 by rj Hey Robin, Thanks for taking the time to write such a detailed answer 🙂!
I still havn't learnt how the output from
Yes, I got the same result regarding the source of the error.
As AkosLukacs suggests, the reason seems to be that it's eventually thrown inside a setTimeout ?
Sure, I'm not blaming anyone for making code for free, and I'm extremely satisfied with the library--I was just explaining that my assertion on JavaScript is that errors should be catchable, but apparently in some cases are not 😊. So I guess the case is closed--I'll never be able to catch it 🤔. Catching the error was my only concern of this thread, fixing the communication is not going to be a problem. Thank you so much for helping out again, you are always very thorough 😁! Posted at 2020-09-28 by AkosLukacs Although the code could be refactored so the Posted at 2020-09-28 by @gfwilliams
http://www.espruino.com/Reference#l_process_uncaughtException So you can catch it - just define a global handler for Posted at 2020-09-28 by rj Yeah, this is what someone suggested on SO as well. If I've understood correctly, callbacks seem to be the general convention used across the project, so I think it would be more correct to have I'll leave messing with the modules to the pros 😊. Posted at 2020-09-28 by rj
I'll take it--thanks 😎! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-09-26 by rj
Hi 👋,
I'm getting this error from time to time when using the "SX127x" module in a couple of projects (custom HW, and ESP32).
I'm not so concerned with why it fails right now (probably bad SPI communication), but I'd like to catch it so I can handle it properly.
I've tried the code below, but I still get
Uncatched Error: ...
in the WEB IDE.Q: Can anyone advise me on how I can catch this error--or is there a more general way to catch errors that happen internally in the Espruino modules 🙂?
Beta Was this translation helpful? Give feedback.
All reactions