diff options
author | Damien George <damien.p.george@gmail.com> | 2015-10-01 17:06:13 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-10-01 17:18:12 +0100 |
commit | 5f3c3ec5e62e64872bfd3f274473db86c2b7fd25 (patch) | |
tree | 7c43560fa441e886e367abf8122085fe22364858 /py/parsenum.c | |
parent | c4489a05433b2878d0598d77bec5d9f6a821ffaa (diff) | |
download | micropython-5f3c3ec5e62e64872bfd3f274473db86c2b7fd25.tar.gz micropython-5f3c3ec5e62e64872bfd3f274473db86c2b7fd25.zip |
py/parsenum: Provide detailed error for int parsing with escaped bytes.
This patch adds more fine grained error message control for errors when
parsing integers (now has terse, normal and detailed). When detailed is
enabled, the error now escapes bytes when printing them so they can be
more easily seen.
Diffstat (limited to 'py/parsenum.c')
-rw-r--r-- | py/parsenum.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/py/parsenum.c b/py/parsenum.c index c6174db65a..1a39c899d5 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -147,9 +147,18 @@ value_error: mp_obj_t exc = mp_obj_new_exception_msg(&mp_type_ValueError, "invalid syntax for integer"); raise_exc(exc, lex); - } else { + } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) { mp_obj_t exc = mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "invalid syntax for integer with base %d: '%.*s'", base, top - str_val_start, str_val_start); + "invalid syntax for integer with base %d", base); + raise_exc(exc, lex); + } else { + vstr_t vstr; + mp_print_t print; + vstr_init_print(&vstr, 50, &print); + mp_printf(&print, "invalid syntax for integer with base %d: ", base); + mp_str_print_quoted(&print, str_val_start, top - str_val_start, true); + mp_obj_t exc = mp_obj_new_exception_arg1(&mp_type_ValueError, + mp_obj_new_str_from_vstr(&mp_type_str, &vstr)); raise_exc(exc, lex); } } |