mstar.utils.client_errors

mstar.utils.client_errors#

Client-visible text for an exception raised while serving a request.

Functions

client_error_text(exc, what, *[, log, ...])

Return (text, error_id): what a client may see for exc.

exception_status_text(exc, what, *[, log])

(status, text) an OpenAI route answers exc with: an exception that carries its own status_code and detail (an HTTPException) keeps both; a ValueError is a refusal, a 400 (or its own status) with server paths cut to base names, logged as one INFO line; anything else goes through client_error_text() (a TypeError a 400 that keeps its traceback, any other a 500 showing only an error id).

scrub_paths(text)

Replace each absolute file path in text with its base name, and a directory path (one ending in "/") with <path>.

mstar.utils.client_errors.client_error_text(exc, what, *, log=logger, type_name=True, traceback=True, refusal=None)[source]#

Return (text, error_id): what a client may see for exc.

A ValueError or TypeError is a refusal raised on purpose, so it keeps its message (prefixed with the type name when type_name), with absolute paths cut to their base names. Anything else becomes internal error (error id <id>). Either way the full error and its traceback (left out when traceback is False, for an error already logged where it happened) go to log as <what> [error id <id>]. refusal overrides that type check, for a caller that knows whether the request was refused.

Parameters:
Return type:

tuple[str, str]

mstar.utils.client_errors.exception_status_text(exc, what, *, log=logger)[source]#

(status, text) an OpenAI route answers exc with: an exception that carries its own status_code and detail (an HTTPException) keeps both; a ValueError is a refusal, a 400 (or its own status) with server paths cut to base names, logged as one INFO line; anything else goes through client_error_text() (a TypeError a 400 that keeps its traceback, any other a 500 showing only an error id). what names the route.

Parameters:
Return type:

tuple[int, str]

mstar.utils.client_errors.scrub_paths(text)[source]#

Replace each absolute file path in text with its base name, and a directory path (one ending in “/”) with <path>.

Parameters:

text (str)

Return type:

str