Skip to content

report() raises AttributeError for a non-string name, breaking the never-raises promise #2

Description

@dmccoystephenson

TraceClient.report() promises it never raises, but a non-string name escapes the try block.

In trace_client/trace_client.py, report() evaluates not name or not name.strip() on the line before its try. Passing a truthy value that is not a str, for example report(123), raises AttributeError: 'int' object has no attribute 'strip' straight into the host program. Reproduced on Python 3.8.10:

>>> c = TraceClient("http://127.0.0.1:1", "app", key="k")
>>> c.report(123)
AttributeError: 'int' object has no attribute 'strip'

The class docstring and the README's "What report promises" table both say report never raises. The type hint says str, but annotations are not enforced, and this is exactly the case the promise exists for.

Suggested fix: run the blank-name check inside the existing try, so a bad name gets dropped and logged at DEBUG the same way any other unqueueable report is.

This issue was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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