Skip to content

Commit

Permalink
Detect and ignore missing library exceptions.
Browse files Browse the repository at this point in the history
This prevents total failure on systems with an architecture not
supported by a PEMicro backend library.
  • Loading branch information
flit committed Mar 20, 2021
1 parent 77cb18c commit 51f7c2e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pyocd_pemicro/pemicro_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
LOG = logging.getLogger(__name__)

TRACE = LOG.getChild("trace")
TRACE.setLevel(logging.INFO)
TRACE.disabled = True

class PEMicroProbe(DebugProbe):
"""! @brief Wraps a PEMicro as a DebugProbe."""
Expand All @@ -58,6 +58,10 @@ class PEMicroProbe(DebugProbe):
APSEL_SHIFT = 24
APSEL_APBANKSEL = APSEL | APBANKSEL

## Part of the error message for exceptions raised when there isn't a PEMicro library
# matching the system's architecture, or other similar reasons.
NO_LIBRARY_ERR = "Unable to find any usable library"

@classmethod
def _get_pemicro(cls):
# PEMicroException is raised by PyPemicro if the PEMicro DLL cannot be found.
Expand All @@ -80,6 +84,10 @@ def get_all_connected_probes(cls, unique_id=None, is_explicit=False):
return []
return [cls(str(info["id"])) for info in port_list]
except PEMicroException as exc:
# Ignore errors about a missing library, which can happen on systems not supported by
# the PEMicro library but on which the plugin is installed.
if cls.NO_LIBRARY_ERR in exc.message:
return []
six.raise_from(cls._convert_exception(exc), exc)

@classmethod
Expand All @@ -94,6 +102,10 @@ def get_probe_with_id(cls, unique_id, is_explicit=False):
else:
return None
except PEMicroException as exc:
# Ignore errors about a missing library, which can happen on systems not supported by
# the PEMicro library but on which the plugin is installed.
if cls.NO_LIBRARY_ERR not in exc.message:
return None
six.raise_from(cls._convert_exception(exc), exc)

def __init__(self, serial_number):
Expand Down

0 comments on commit 51f7c2e

Please sign in to comment.