Skip to main content

Exceptions

Every graphlens error derives from a single base, GraphLensError, so you can catch the whole family with one except.

from graphlens import (
GraphLensError,
AdapterError,
AdapterNotFoundError,
DuplicateNodeError,
DiscoveryError,
BackendError,
SerializationError,
)

Hierarchy

GraphLensError
├── AdapterNotFoundError
├── AdapterError
├── DuplicateNodeError
├── DiscoveryError
├── BackendError
└── SerializationError
ExceptionRaised when
GraphLensErrorBase class for all graphlens errors
AdapterNotFoundErroradapter_registry.load(name) finds no adapter for name
AdapterErrorAn adapter fails during execution — including analyze(..., strict=True) when the resolver status is not ok
DuplicateNodeErrorGraphLens.add_node is given a node whose id already exists
DiscoveryErrorProject discovery fails
BackendErrorA graph backend operation (store/clear) fails
SerializationErrorGraph (de)serialization fails — e.g. loading a payload with an incompatible schema version

Handling them

Catch the base class to handle any graphlens failure uniformly:

from graphlens import GraphLensError, adapter_registry

try:
adapter = adapter_registry.load("python")()
graph = adapter.analyze("./my-project", strict=True)
except GraphLensError as exc:
print(f"graphlens failed: {exc}")
raise

Or be specific when you can recover:

from graphlens import AdapterNotFoundError, adapter_registry

try:
adapter = adapter_registry.load(lang)()
except AdapterNotFoundError:
print(f"No adapter for {lang!r}. Available: {adapter_registry.available()}")