Skip to content

Commit 8b10863

Browse files
committed
Merge branch 'catch_coredump_except' into 'master'
fix: Catch all exceptions from esp-coredump package to avoid exiting monitor See merge request espressif/esp-idf-monitor!82
2 parents 9821a2a + af197bd commit 8b10863

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

esp_idf_monitor/base/coredump.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .constants import TAG_KEY
1111
from .logger import Logger # noqa: F401
12-
from .output_helpers import note_print, warning_print
12+
from .output_helpers import error_print, note_print, warning_print
1313
from .web_socket_client import WebSocketClient # noqa: F401
1414

1515
# coredump related messages
@@ -65,14 +65,6 @@ def _process_coredump(self): # type: () -> None
6565
else:
6666
try:
6767
import esp_coredump
68-
except ImportError as e:
69-
warning_print('Failed to parse core dump info: '
70-
f'Module {e.name} is not installed\n\n')
71-
self.logger.output_enabled = True
72-
self.logger.print(COREDUMP_UART_START + b'\n')
73-
self.logger.print(self._coredump_buffer)
74-
# end line will be printed in handle_serial_input
75-
else:
7668
coredump = esp_coredump.CoreDump(core=coredump_file.name, core_format='b64', prog=self.elf_files)
7769
f = io.StringIO()
7870
with redirect_stdout(f):
@@ -81,12 +73,27 @@ def _process_coredump(self): # type: () -> None
8173
self.logger.output_enabled = True
8274
self.logger.print(output.encode('utf-8'))
8375
self.logger.output_enabled = False # Will be re-enabled in check_coredump_trigger_after_print
76+
except ImportError as e:
77+
warning_print('Failed to parse core dump info: '
78+
f'Module {e.name} is not installed\n\n')
79+
self._print_unprocessed_coredump()
80+
except (Exception, SystemExit) as e:
81+
error_print(f'Failed to parse core dump info: {e}\n\n')
82+
self._print_unprocessed_coredump()
83+
8484
if coredump_file is not None:
8585
try:
8686
os.unlink(coredump_file.name)
8787
except OSError as e:
8888
warning_print(f'Couldn\'t remote temporary core dump file ({e})')
8989

90+
def _print_unprocessed_coredump(self) -> None:
91+
"""Print unprocessed core dump data if there was any issue during processing."""
92+
self.logger.output_enabled = True
93+
self.logger.print(COREDUMP_UART_START + b'\n')
94+
self.logger.print(self._coredump_buffer)
95+
# end line will be printed in handle_serial_input
96+
9097
def _check_coredump_trigger_before_print(self, line): # type: (bytes) -> None
9198
if self._decode_coredumps == COREDUMP_DECODE_DISABLE:
9299
return

0 commit comments

Comments
 (0)