Skip to content

Throw meaningful exceptions in run() #61

@whotwagner

Description

@whotwagner

Currently I have the following error log:

[2026-02-23 12:14:22,189] ERROR detectors.RandomDetector.f07f2ba3d1d8564397e53a42e328ab12: Engine error during process: -1
Traceback (most recent call last):
  File "/app/src/service/features/engine.py", line 187, in _run_loop
    out = self.processor.process(raw)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/src/service/core.py", line 173, in process
    return self.library_component.process(raw_message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/detectmatelibrary/common/core.py", line 117, in process
    return_schema = self.run(input_=data_buffered, output_=output_)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/detectmatelibrary/common/detector.py", line 110, in run
    if (anomaly_detected := self.detect(input_=input_, output_=output_)):
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/detectmatelibrary/detectors/random_detector.py", line 45, in detect
    event_config = self.config.events[input_["EventID"]]
                   ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: -1

Even though this occured due to a misconfiguration, we should handle exceptions gracefully. in the service (service/features/engine.py line 187) this error is caught as a generall "Exception". I strongly believe that we should catch this error first in the library(detectmatelibrary/common/core.py line 118) and raise custom exceptions so that the service can distinguish and print meaningful error-messages for the user.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions