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

Base return types for generator errors #154

Closed
wants to merge 2 commits into from

Conversation

tylerjrich
Copy link

There are a couple methods in the puppetdb API which return empty lists instead of 404s when querying an invalid value, two of these being queries for a particular fact name of a node (/pdb/query/v4/nodes//facts/), or a resource type/name (/pdb/query/v4/resources//<TITLE>)

In the types objects for pypuppetdb, these two queries used a return next(x for x in y) type pattern, however since the API returns an empty list, the implied generator starts out empty, and instead of returning a valid object, raises a StopIteration, which is not handled by pypuppetdb.

For the end user, this is extremely confusing, as a StopIteration doesn't behave like a standard exception. I've added in a default case to the next() method to return the empty list in case of an invalid result, which mimics the behavior of the puppetdb API.

While I have managed to manually test these changes against my own puppet infrastructure, there doesn't seem to be an easy way for me to add unit tests for the changes given the current pytest fixtures available, as the Node.fact() method relies on the underlying baseapi.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 85.213% when pulling 4d23286 on tylerjrich:missing-fact into 1fae0a3 on voxpupuli:master.

Copy link
Contributor

@othalla othalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some unit test regarding the stopiteration error?

@othalla
Copy link
Contributor

othalla commented Aug 28, 2019

@tylerjrich could you check for some unit tests?

@bastelfreak
Copy link
Member

HI,
I'm going to close this PR due to inactivity. @tylerjrich please feel free to reopen and address the comments if you're still interested in this PR.

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

Successfully merging this pull request may close these issues.

4 participants