OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Python API referencev12.0

errors — functions

Status codes in, exceptions out, in one place.

The C ABI has exactly one error convention: every fallible function returns optris_sdk_status, zero is success and nothing else is, and after a failure optris_sdk_last_error_message() describes what went wrong on the calling thread. Python wants exceptions.

The translation happens here and nowhere else. Every call in this package goes through check, so there is one place that decides what a status means and one place that reads the message -- and the message is read immediately, while it is still the failure's own, because it is per-thread state that the next failing call overwrites.

The exception classes mirror the status codes rather than inventing a taxonomy. A caller who wants to know exactly what happened reads exc.status; a caller who wants the common cases catches NotFoundError or TimeoutError by name. Everything derives from SdkError, so except SdkError is always enough to contain the SDK.

busy_reason_name(reason)

A busy reason as a word, for printing.

unmapped_statuses()

Status constants the ABI defines that this module does not map.

Empty, and there is a test that keeps it empty. Without one, the claim that every status has a class is a comment rather than a fact -- a status added to the ABI would quietly arrive as the base class, which is exactly the outcome the named subclasses exist to avoid.

status_name(status)

The SDK's own spelling of a status code.

last_error_message()

What went wrong on this thread, or an empty string.

Per-thread by the ABI's guarantee, so a failure on one thread never reports another's.

last_error_status()

The status of the last failure on this thread, or success.

The companion to last_error_message, and the half that is machine-readable. Per-thread, like the message, so a failure on one thread is never reported on another.

Rarely needed from Python, where every call raises and the exception already carries status. It is here for the two cases an exception cannot cover: after check has been bypassed -- a raw _lib call in a test or a diagnostic -- and inside an except block, to confirm that the status the SDK recorded is the one the exception reports.

OPTRIS_SDK_OK means no failure has been recorded on this thread since the last time one was cleared, not that the last call succeeded: a successful call does not reset it. Use clear_last_error to establish a known starting point.

clear_last_error()

Forget the failure recorded on this thread.

Afterwards last_error_status reports success and last_error_message is empty. Useful before a call whose failure you intend to inspect through them rather than through an exception, so that what you read cannot be an older failure's.

last_busy_report()

Why the calling thread's most recent busy refusal happened.

Read it immediately after a call failed with OPTRIS_SDK_ERROR_BUSY, on the same thread, exactly as last_error_message is read. Thread-local, so a failure on one thread never reports another's.

Mostly unnecessary from Python, because check reads it for you and BusyError arrives carrying the answer. It is here for a caller reading the thread's state directly -- and because the two halves of that pair, the exception's fields and this call, must agree.

Cleared by every subsequent call on this thread, successful or not, so a stale reason can never be read as the cause of an unrelated error. After a non-busy failure the reason is BUSY_REASON_UNKNOWN and both strings are empty.

check(status, function)

Raise unless status is success.

Every call in this package is wrapped in this. The message is read here, immediately after the failure, because it is per-thread state and the next failing call on this thread replaces it.

The same is true of the busy detail, which is why a OPTRIS_SDK_ERROR_BUSY is read here as well rather than left for the caller to fetch: by the time an except block runs, any other SDK call on this thread has already cleared it.