Skip to content

Commit

Permalink
trunner: provide traceback for internal exceptions when waiting for plo
Browse files Browse the repository at this point in the history
JIRA: CI-362
  • Loading branch information
damianloew committed Nov 2, 2023
1 parent a37c915 commit aed2461
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions trunner/harness/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def __str__(self) -> str:
err.extend([bold("OUTPUT:"), self.output])

err.extend(self._format_additional_info())

if self.traceback:
err.append(bold("TRACEBACK:"))
err.extend([self.traceback])

err.append("")
return "\n".join(err)

Expand Down
13 changes: 11 additions & 2 deletions trunner/tools/phoenix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import signal
import threading
import time
import traceback
import pexpect

from trunner.harness import ProcessError
from typing import Optional
from serial.tools import list_ports
from contextlib import contextmanager
from .common import add_output_to_exception
Expand All @@ -24,7 +26,7 @@ def wait_for_vid_pid(vid: int, pid: int, timeout=0):
found_ports = [port for port in list_ports.comports() if port.pid == pid and port.vid == vid]

if len(found_ports) > 1:
raise Exception(
raise ValueError(
"More than one plo port was found! Maybe more than one device is connected? Hint used to find port:"
f"{vid:04x}:{pid:04x}"
)
Expand Down Expand Up @@ -79,6 +81,10 @@ def run(self):
class PhoenixdError(ProcessError):
name = "PHOENIXD"

def __init__(self, msg: str = "", output: Optional[str]=None, traceback=None):

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.9)

E252 missing whitespace around parameter equals

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.9)

E252 missing whitespace around parameter equals

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.10)

E252 missing whitespace around parameter equals

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.10)

E252 missing whitespace around parameter equals

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.11)

E252 missing whitespace around parameter equals

Check failure on line 84 in trunner/tools/phoenix.py

View workflow job for this annotation

GitHub Actions / build (3.11)

E252 missing whitespace around parameter equals
super().__init__(msg, output)
self.traceback = traceback


class Phoenixd:
"""Handler for phoenixd process"""
Expand Down Expand Up @@ -119,8 +125,11 @@ def _run(self):
# such wait avoids a following issue with loading an app:
# https://github.com/phoenix-rtos/phoenix-rtos-project/issues/545
time.sleep(0.5)
except (TimeoutError, Exception) as exc:
except (TimeoutError, ValueError) as exc:
raise PhoenixdError(str(exc)) from exc
except Exception as exc:
# add traceback if it's an internal exception
raise PhoenixdError(str(exc), traceback=traceback.format_exc()) from exc

# Use pexpect.spawn to run a process as PTY, so it will flush on a new line
self.proc = pexpect.spawn(
Expand Down

0 comments on commit aed2461

Please sign in to comment.