From c087939c086237fb093ef040c0b1dbca3eca716a Mon Sep 17 00:00:00 2001 From: David <2889367+daveleroy@users.noreply.github.com> Date: Sat, 1 Apr 2023 03:38:11 -0700 Subject: [PATCH] Don't show an error when attempting to stop the debugger when there is no active session to stop --- modules/core/error.py | 6 ++++-- modules/dap/__init__.py | 5 ++++- modules/dap/error.py | 2 ++ modules/debugger.py | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/core/error.py b/modules/core/error.py index f1a52bee..b7bb15e8 100644 --- a/modules/core/error.py +++ b/modules/core/error.py @@ -1,5 +1,7 @@ from __future__ import annotations class Error(Exception): - def __init__(self, format: str): - super().__init__(format) + message = 'Unknown Error Occured' + + def __init__(self, message: str|None = None): + super().__init__(message or self.message or 'Unknown Error Occured') diff --git a/modules/dap/__init__.py b/modules/dap/__init__.py index 6361dcc4..0f61d621 100644 --- a/modules/dap/__init__.py +++ b/modules/dap/__init__.py @@ -4,7 +4,10 @@ SourceLocation, ) -from .error import Error, Json +from .error import ( + Error, + NoActiveSessionError, +) from .dap import ( StackFrame, diff --git a/modules/dap/error.py b/modules/dap/error.py index e7d3b2a3..215695c3 100644 --- a/modules/dap/error.py +++ b/modules/dap/error.py @@ -31,3 +31,5 @@ def from_message(message: dap.Message): return Error(format, message.url, message.urlLabel) +class NoActiveSessionError(core.Error): + message = 'No Active Debug Session' diff --git a/modules/debugger.py b/modules/debugger.py index 7ac1fca2..791574ec 100644 --- a/modules/debugger.py +++ b/modules/debugger.py @@ -452,6 +452,7 @@ async def stop(self, session: dap.Session|None = None) -> None: await session_stop + except dap.NoActiveSessionError: ... except core.Error as e: self.console.error(f'Unable to stop: {e}') @property @@ -461,7 +462,7 @@ def is_active(self): @property def active(self): if not self.session: - raise core.Error('No Active Debug Sessions') + raise dap.NoActiveSessionError() return self.session @active.setter