Skip to content

Commit 336a498

Browse files
committed
generalize some exceptions
1 parent f820835 commit 336a498

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

robotcode/debugger/debugger.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class StackTraceResult(NamedTuple):
112112
total_frames: int
113113

114114

115+
class InvalidThreadId(Exception):
116+
def __init__(self, thread_id: Any) -> None:
117+
super().__init__(f"Invalid thread id {thread_id}")
118+
119+
115120
class StackFrameEntry:
116121
def __init__(
117122
self,
@@ -294,7 +299,7 @@ def stop(self) -> None:
294299
@_logger.call
295300
def continue_thread(self, thread_id: int) -> None:
296301
if self.main_thread is None or thread_id != self.main_thread.ident:
297-
raise RuntimeError("Invalid threadId")
302+
raise InvalidThreadId(thread_id)
298303

299304
with self.condition:
300305
self.state = State.Running
@@ -303,7 +308,7 @@ def continue_thread(self, thread_id: int) -> None:
303308
@_logger.call
304309
def pause_thread(self, thread_id: int) -> None:
305310
if self.main_thread is None or thread_id != self.main_thread.ident:
306-
raise RuntimeError("Invalid threadId")
311+
raise InvalidThreadId(thread_id)
307312

308313
with self.condition:
309314
self.requested_state = RequestedState.Pause
@@ -314,7 +319,7 @@ def pause_thread(self, thread_id: int) -> None:
314319
@_logger.call
315320
def next(self, thread_id: int, granularity: Optional[SteppingGranularity] = None) -> None:
316321
if self.main_thread is None or thread_id != self.main_thread.ident:
317-
raise RuntimeError("Invalid threadId")
322+
raise InvalidThreadId(thread_id)
318323

319324
with self.condition:
320325
self.state = State.Running
@@ -346,7 +351,7 @@ def step_in(
346351
self, thread_id: int, target_id: Optional[int] = None, granularity: Optional[SteppingGranularity] = None
347352
) -> None:
348353
if self.main_thread is None or thread_id != self.main_thread.ident:
349-
raise RuntimeError("Invalid threadId")
354+
raise InvalidThreadId(thread_id)
350355

351356
with self.condition:
352357
self.requested_state = RequestedState.StepIn
@@ -357,7 +362,7 @@ def step_in(
357362
@_logger.call
358363
def step_out(self, thread_id: int, granularity: Optional[SteppingGranularity] = None) -> None:
359364
if self.main_thread is None or thread_id != self.main_thread.ident:
360-
raise RuntimeError("Invalid threadId")
365+
raise InvalidThreadId(thread_id)
361366

362367
with self.condition:
363368
self.requested_state = RequestedState.StepOut
@@ -384,7 +389,7 @@ def step_out(self, thread_id: int, granularity: Optional[SteppingGranularity] =
384389
self.condition.notify_all()
385390

386391
@event
387-
def send_event(sender, event: Event) -> None:
392+
def send_event(sender, event: Event) -> None: # NOSONAR
388393
...
389394

390395
def set_breakpoints(
@@ -862,6 +867,9 @@ def get_stack_trace(
862867
levels: Optional[int] = None,
863868
format: Optional[StackFrameFormat] = None,
864869
) -> StackTraceResult:
870+
if self.main_thread is None or thread_id != self.main_thread.ident:
871+
raise InvalidThreadId(thread_id)
872+
865873
start_frame = start_frame or 0
866874
levels = start_frame + (levels or len(self.stack_frames))
867875

0 commit comments

Comments
 (0)