Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String formatting errors in exception arguments #966

Closed
AnthonyHorton opened this issue Apr 16, 2020 · 5 comments · Fixed by #983
Closed

String formatting errors in exception arguments #966

AnthonyHorton opened this issue Apr 16, 2020 · 5 comments · Fixed by #983

Comments

@AnthonyHorton
Copy link
Collaborator

Describe the bug
In POCS there are a few instance of

raise ValueError("Blah, blah, blah, {}!", obj)

where it should be

raise ValueError("Blah, blah, blah, {}!".format(obj))

or

raise ValueError(f"Blah, blah, blah, {obj}!"), e.g.

"No focus exposure time specified, aborting autofocus of {}!", self._camera)
and
"No focus thumbnail size specified, aborting autofocus of {}!", self._camera)

These don't cause problems in POCS itself (beyond some funny looking exceptions) but they do cause problems for the remote cameras in huntsman-pocs, because the Pyro4 network layer ends up trying to serialise ValueErrors that contain, in their args list, a reference to an object that it can't serialise, resulting in opaque 'circular reference' exceptions from Pyro.

@wtgee
Copy link
Member

wtgee commented Apr 16, 2020

Thanks for reporting!

@AnthonyHorton
Copy link
Collaborator Author

AnthonyHorton commented Apr 17, 2020

For extra credit someone should craft a regular expression for finding all instances of this! I've found four so far, but I'm not sure that's all of them.

Edit: self nerd-snipe! The regular expression }.*(["']), [^\1]+\) finds 102 matches in the POCS codebase. There are definitely a few false positives, but most of them seem to be string formatting mistakes!

@wtgee
Copy link
Member

wtgee commented May 29, 2020

Related to this we also have a number of places where we are still passing multiple arguments to the logger, as in:

self.logger.debug("Here's some foo", bar)

They are also not really causing problems but it would be good to get them switched to f-strings.

@wtgee
Copy link
Member

wtgee commented Jun 1, 2020

I tried to take care of a lot of these in #951.

@wtgee
Copy link
Member

wtgee commented Jul 7, 2020

I think I got the rest of these in #983. The regex doesn't turn up anything else. Feel free to reopen.

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

Successfully merging a pull request may close this issue.

2 participants