Skip to content

A non-string constructor argument raises an AttributeError that does not name the argument #33

Closed

Description

@dmccoystephenson

A truthy non-string base_url, application, version, key or install_id makes the TraceClient constructor raise AttributeError from a .strip() call, and the message does not say which argument was wrong. The argument checks at trace_client/trace_client.py:140-154 only handle missing, blank and overlong values.

Reproduced on Python 3.8.10:

Call Result
TraceClient(url, "a", 1.4) AttributeError: 'float' object has no attribute 'strip'
TraceClient(url, "a", "1", key=123) AttributeError: 'int' object has no attribute 'strip'
TraceClient(url, "a", "1", install_id=7) AttributeError: 'int' object has no attribute 'strip'
TraceClient(url, 5, "1") AttributeError: 'int' object has no attribute 'strip'

base_url takes the same path by inspection of line 140; it was not run.

This is a realistic failure: a YAML settings file turns version: 1.4 into a float and an all-digit key into an int. The checks run before the opt-outs, so a program also stops at startup when reporting is disabled, including under DO_NOT_TRACK=1. test_constructor_errors_name_the_argument_they_reject expects every constructor error to start with the argument name, but it covers only blank and overlong values.

The same gap in report() was closed by #2. This one is separate, since the constructor is the path that is allowed to raise.

Suggested fix: check that each of these arguments is a string (or None where that is allowed) before trimming, and raise a ValueError that names the argument, such as version must be a string, so the existing rule holds. Accepting a number by converting it with str() is the alternative, but it would hide the mistake. The fix changes nothing on the wire. Whether trace-client-java needs a counterpart was not verified, because its source could not be read from this session.

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


drafted by Claude on behalf of Daniel Stephenson

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