mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[code] Print errors in the Python console.
Change-Id: If3a096ee46105229b6c4c77906826e78666cdc11
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
CodeApp = "Python"
|
CodeApp = "Python"
|
||||||
CodeAppCapital = "PYTHON"
|
CodeAppCapital = "PYTHON"
|
||||||
ConsolePrompt = ">>> "
|
ConsolePrompt = ">>> "
|
||||||
ConsoleError = "Error"
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
#define MICROPY_REPL_EVENT_DRIVEN (0)
|
#define MICROPY_REPL_EVENT_DRIVEN (0)
|
||||||
#define MICROPY_HELPER_REPL (1)
|
#define MICROPY_HELPER_REPL (1)
|
||||||
#define MICROPY_HELPER_LEXER_UNIX (0)
|
#define MICROPY_HELPER_LEXER_UNIX (0)
|
||||||
#define MICROPY_ENABLE_SOURCE_LINE (0)
|
#define MICROPY_ENABLE_SOURCE_LINE (1)
|
||||||
#define MICROPY_ENABLE_DOC_STRING (0)
|
#define MICROPY_ENABLE_DOC_STRING (0)
|
||||||
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
|
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
|
||||||
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
|
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
|
||||||
#define MICROPY_PY_ASYNC_AWAIT (0)
|
#define MICROPY_PY_ASYNC_AWAIT (0)
|
||||||
#define MICROPY_PY_BUILTINS_BYTEARRAY (0)
|
#define MICROPY_PY_BUILTINS_BYTEARRAY (0)
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "py/builtin.h"
|
#include "py/builtin.h"
|
||||||
|
#include "py/compile.h"
|
||||||
|
#include "py/gc.h"
|
||||||
|
#include "py/lexer.h"
|
||||||
|
#include "py/mperrno.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "py/nlr.h"
|
#include "py/nlr.h"
|
||||||
#include "py/compile.h"
|
|
||||||
#include "py/lexer.h"
|
|
||||||
#include "py/runtime.h"
|
|
||||||
#include "py/repl.h"
|
#include "py/repl.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
#include "py/stackctrl.h"
|
#include "py/stackctrl.h"
|
||||||
#include "py/gc.h"
|
|
||||||
#include "py/mperrno.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <apps/i18n.h>
|
#include <apps/i18n.h>
|
||||||
@@ -38,10 +38,40 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
|||||||
mp_call_function_0(module_fun);
|
mp_call_function_0(module_fun);
|
||||||
mp_hal_set_interrupt_char(-1); // Disable interrupt
|
mp_hal_set_interrupt_char(-1); // Disable interrupt
|
||||||
nlr_pop();
|
nlr_pop();
|
||||||
} else {
|
} else { // Uncaught exception
|
||||||
// Uncaught exception
|
/* mp_obj_print_exception is supposed to handle error printing. However,
|
||||||
//return (mp_obj_t) nlr.ret_val;
|
* because we want to print custom information, we copied and modified the
|
||||||
printText(I18n::translate(I18n::Message::ConsoleError), 5);
|
* content of mp_obj_print_exception instead of calling it. */
|
||||||
|
if (mp_obj_is_exception_instance((mp_obj_t)nlr.ret_val)) {
|
||||||
|
size_t n, *values;
|
||||||
|
mp_obj_exception_get_traceback((mp_obj_t)nlr.ret_val, &n, &values);
|
||||||
|
if (n > 0) {
|
||||||
|
assert(n % 3 == 0);
|
||||||
|
for (int i = n - 3; i >= 0; i -= 3) {
|
||||||
|
if (values[i] != 0 || i == 0) {
|
||||||
|
if (values[i] == 0) {
|
||||||
|
mp_printf(&mp_plat_print, " Last command\n");
|
||||||
|
} else {
|
||||||
|
#if MICROPY_ENABLE_SOURCE_LINE
|
||||||
|
mp_printf(&mp_plat_print, " File \"%q\", line %d", values[i], (int)values[i + 1]);
|
||||||
|
#else
|
||||||
|
mp_printf(&mp_plat_print, " File \"%q\"", values[i]);
|
||||||
|
#endif
|
||||||
|
// the block name can be NULL if it's unknown
|
||||||
|
qstr block = values[i + 2];
|
||||||
|
if (block == MP_QSTR_NULL) {
|
||||||
|
mp_print_str(&mp_plat_print, "\n");
|
||||||
|
} else {
|
||||||
|
mp_printf(&mp_plat_print, ", in %q\n", block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp_obj_print_helper(&mp_plat_print, (mp_obj_t)nlr.ret_val, PRINT_EXC);
|
||||||
|
mp_print_str(&mp_plat_print, "\n");
|
||||||
|
/* End of mp_obj_print_exception. */
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(sCurrentExecutionEnvironment == this);
|
assert(sCurrentExecutionEnvironment == this);
|
||||||
|
|||||||
Reference in New Issue
Block a user