Skip to content

The API client writes the raw response body to stderr before the JSON error message #21

Description

@ClassicMMT

What happens

Every failed request writes two lines to stderr. The client log line comes
first. The JSON error message from the CLI comes second.

$ dm run status 999999
Error when calling API: {'detail': 'The requested run was not found.'}
{"error": {"code": "error", "message": "Request failed: The requested run was not found."}}

Why this is a problem

The README says that stderr carries only the JSON error message. A parser
that reads stderr as JSON fails on the first line. The line contains the full
response body, so a server 500 puts its complete error page on stderr. That
page can be some hundreds of kilobytes.

Cause

_raise_for_status in datamasque-python logs the full response body at
ERROR level. The CLI adds no handler to the datamasque logger. The
last-resort handler in Python then prints the record to stderr.

Suggested fix

Add these two lines to main():

logging.getLogger("datamasque").addHandler(logging.NullHandler())
logging.getLogger("datamasque").propagate = False

Source

Found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions