Skip to content

Commit c2f0a75

Browse files
committed
E.setFlags({onErrorSave:true}) now saves any uncaught errors to a file in Storage called ERROR (#2583)
E.setFlags({onErrorFlash:true}) now flashes the red LED for 200ms on any uncaught errors
1 parent 21f1f46 commit c2f0a75

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

ChangeLog

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
Add a backtrace command to debugger, add console.trace command, set Error.stack in constructor (fix #2490)
99
Error.stack/stack dump now uses more standard file:line:col format
1010
Out of memory errors now show a backtrace (previously it was very hard to track these down)
11-
Increase chars shown in strings in console to 60
12-
The first Uncaught error is now saved to a file in Storage called ERROR (`E.setFlags({noErrorSave:true})` disables this) (#2583)
11+
Increase chars shown in strings in console to 60
1312
If debugging via bluetooth and we disconnect, quit debugging (locks Bluetooth otherwise)
1413
Remove Line Number handling code (most code will be run out of Storage now, where we know the line number)
1514
Debugger now uses jslPrintPosition to print file+line+col, is aware of Modules.addCached that IDE adds and discounts it
@@ -21,6 +20,8 @@
2120
E.defrag() now defrags everything, including Flat Strings (fix #1740)
2221
ESP32: Fix 2v26 regression which stopped many pins from being watched
2322
Puck.js: Revert second timer accuracy tweak that broke Puck.IR in 2v26
23+
E.setFlags({onErrorSave:true}) now saves any uncaught errors to a file in Storage called ERROR (#2583)
24+
E.setFlags({onErrorFlash:true}) now flashes the red LED for 200ms on any uncaught errors
2425

2526
2v26 : nRF5x: ensure TIMER1_IRQHandler doesn't always wake idle loop up (fix #1900)
2627
Puck.js: On v2.1 ensure Puck.mag behaves like other variants - just returning the last reading (avoids glitches when used with Puck.magOn)

src/jsflags.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ typedef enum {
2727
#ifdef ESPR_JIT
2828
JSF_JIT_DEBUG = 1<<4, ///< When JIT enabled, output debugging info
2929
#endif
30-
JSF_NO_ERRORS_SAVE = 1<<5, ///< If set, do not attempt to save errors to internal Storage
30+
JSF_ON_ERROR_SAVE = 1<<5, ///< If set, save error and stack trace to an 'ERROR' file in internal Storage
31+
JSF_ON_ERROR_FLASH_LED = 1<<6, ///< If set, when we get an error, flash the Red LED
3132
} PACKED_FLAGS JsFlags;
3233

3334

34-
#define JSFLAG_NAMES "deepSleep\0unsafeFlash\0unsyncFiles\0pretokenise\0jitDebug\0noErrorSave\0"
35+
#define JSFLAG_NAMES "deepSleep\0unsafeFlash\0unsyncFiles\0pretokenise\0jitDebug\0onErrorSave\0onErrorFlash\0"
3536
// NOTE: \0 also added by compiler - two \0's are required!
3637

3738
extern volatile JsFlags jsFlags;

src/jsinteractive.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,8 +1299,15 @@ void jsiCheckErrors(bool wasREPL) {
12991299
jsiConsolePrintf("Uncaught %v\n", exception);
13001300
reportedError = true;
13011301
#ifndef SAVE_ON_FLASH
1302+
#ifdef LED1_PININDEX
1303+
if (jsfGetFlag(JSF_ON_ERROR_FLASH_LED)) {
1304+
Pin pin = LED1_PININDEX;
1305+
jshPinOutput(pin, LED1_ONSTATE);
1306+
jstPinOutputAtTime(jshGetTimeFromMilliseconds(200), NULL, &pin, 1, !LED1_ONSTATE);
1307+
}
1308+
#endif
13021309
JsVar *exceptionString = NULL;
1303-
if ((!jsfGetFlag(JSF_NO_ERRORS_SAVE)) && !jsfFindFile(jsfNameFromString("ERROR"),NULL))
1310+
if (jsfGetFlag(JSF_ON_ERROR_SAVE) && !jsfFindFile(jsfNameFromString("ERROR"),NULL))
13041311
exceptionString = jsvAsString(exception);
13051312
#endif
13061313

src/jswrap_espruino.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,10 @@ code.
852852
after each command (the default is *to* flush). This is much faster, but can
853853
cause filesystem damage if power is lost without the filesystem unmounted.
854854
* `jitDebug` - When JIT compiling, outputs debug info to the console
855-
* `noErrorSave` - [2v27+] when an uncaught error occurs, by default it is now
856-
written to a file called `ERROR` in Storage (the file is not updated). To
857-
stop this happening, use `E.setFlags({noErrorSave:true})`
855+
* `onErrorSave` - [2v27+] when an uncaught error occurs, write it to a
856+
file called `ERROR` in Storage (the file is not updated)
857+
* `onErrorFlash` - [2v27+] when an uncaught error occurs, flash the red LED
858+
for 200ms (only on devices with a physical LED)
858859
*/
859860
/*JSON{
860861
"type" : "staticmethod",
@@ -1671,7 +1672,7 @@ void jswrap_e_dumpVariables() {
16711672
"name" : "defrag",
16721673
"generate" : "jsvDefragment"
16731674
}
1674-
This defragment's Espruino's memory.
1675+
This defragment's Espruino's memory.
16751676
16761677
While Espruino does a lot of work to avoid fragmentation (variables spread over memory)
16771678
and can usually work around it (such as by allocating data in chunks) sometimes

0 commit comments

Comments
 (0)