Skip to content

Commit 86f4014

Browse files
committed
Add exception filename to title bar
Add the exception filename after the line number and change the line number so it is in that file. It used to always be code.py. Fixes #6702
1 parent f1826b0 commit 86f4014

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ void supervisor_execution_status(void) {
213213
if (_current_executing_filename != NULL) {
214214
serial_write(_current_executing_filename);
215215
} else if ((_exec_result.return_code & PYEXEC_EXCEPTION) != 0 &&
216+
_exec_result.exception_line > 0 &&
216217
exception != NULL) {
217-
mp_printf(&mp_plat_print, "@%d %q", _exec_result.exception_line, exception->base.type->name);
218+
mp_printf(&mp_plat_print, "@%d %s %q", _exec_result.exception_line, _exec_result.exception_filename, exception->base.type->name);
218219
} else {
219220
serial_write_compressed(translate("Done"));
220221
}

shared/runtime/pyexec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
199199
size_t n, *values;
200200
mp_obj_exception_get_traceback(return_value, &n, &values);
201201
if (values != NULL) {
202-
result->exception_line = values[n - 2];
202+
result->exception_line = values[1];
203+
result->exception_filename[sizeof(result->exception_filename) - 1] = '\0';
204+
strncpy(result->exception_filename, qstr_str(values[0]), sizeof(result->exception_filename) - 1);
203205
}
204206
}
205207
}

shared/runtime/pyexec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ typedef struct {
3737
int return_code;
3838
mp_obj_t exception;
3939
int exception_line;
40+
// Only store the first 32 characters of the filename. It is very unlikely that they can all be
41+
// seen.
42+
char exception_filename[33];
4043
} pyexec_result_t;
4144

4245
extern pyexec_mode_kind_t pyexec_mode_kind;

0 commit comments

Comments
 (0)