Skip to content

Typed exception hierarchy instead of bare Exception #47

Closed

Description

@tipatterson-dev

Sub-issue of #46.

Problem

Every failure the library raises deliberately is a bare Exception:

  • resources/system.py:401 — add_insert_datastream()
  • resources/system.py:449 — add_insert_controlstream()
  • resources/system.py:533 — add_and_insert_control_stream()
  • resources/system.py:574 — insert_self()
  • resources/datastream.py:113 — insert_observation_dict()

A caller cannot distinguish an OSHConnect failure from a bug in its own code — except Exception is the only option, and it catches KeyError, AttributeError, and everything else along with it. Downstream code that wants "retry on server rejection, crash on programming error" has no way to express it.

Reproduce

try:
    system.insert_self()
except Exception as e:      # the only thing that works today
    ...                     # also catches the KeyError from #44

There is no oshconnect.exceptions module to import from.

Possible fix

Add src/oshconnect/exceptions.py with a small hierarchy, all rooted at a base subclassing Exception so existing except Exception: callers are unaffected:

OSHConnectError(Exception)
├── ResourceInsertError    # non-ok response to a create POST
│   └── carries .status_code, .response_text, .resource_type
└── ConfigurationError     # e.g. unregistered node (#43)

Convert the five sites above, and export the names from oshconnect/__init__.py. Message text should stay as-is — the current messages already carry status code and body, which is the useful part.

Blocks nothing, but #43 and #44 both want to raise something and should land after this so they use the typed form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions