10000 py: Fix SyntaxError exception: don't have a block name, so pass NULL. · lurch/micropython@0e4ba25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e4ba25

Browse files
committed
py: Fix SyntaxError exception: don't have a block name, so pass NULL.
1 parent 73496fb commit 0e4ba25

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

py/obj.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ void mp_obj_print_exception(mp_obj_t exc) {
5555
printf("Traceback (most recent call last):\n");
5656
for (int i = n - 3; i >= 0; i -= 3) {
5757
#if MICROPY_ENABLE_SOURCE_LINE
58-
printf(" File \"%s\", line %d, in %s\n", qstr_str(values[i]), (int)values[i + 1], qstr_str(values[i + 2]));
58+
printf(" File \"%s\", line %d", qstr_str(values[i]), (int)values[i + 1]);
5959
#else
60-
printf(" File \"%s\", in %s\n", qstr_str(values[i]), qstr_str(values[i + 2]));
60+
printf(" File \"%s\"", qstr_str(values[i]));
6161
#endif
62+
// the block name can be NULL if it's unknown
63+
qstr block = values[i + 2];
64+
if (block == MP_QSTR_NULL) {
65+
printf("\n");
66+
} else {
67+
printf(", in %s\n", qstr_str(block));
68+
}
6269
}
6370
}
6471
}

py/parsehelper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ mp_obj_t mp_parse_make_exception(mp_lexer_t *lex, mp_parse_error_kind_t parse_er
6161
}
6262

6363
// add traceback to give info about file name and location
64-
mp_obj_exception_add_traceback(exc, mp_lexer_source_name(lex), mp_lexer_cur(lex)->src_line, mp_lexer_cur(lex)->src_column);
64+
// we don't have a 'block' name, so just pass the NULL qstr to indicate this
65+
mp_obj_exception_add_traceback(exc, mp_lexer_source_name(lex), mp_lexer_cur(lex)->src_line, MP_QSTR_NULL);
6566

6667
return exc;
6768
}

0 commit comments

Comments
 (0)
0