-
Notifications
You must be signed in to change notification settings - Fork 41
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
Snap Get - Error on no value set #87
Comments
Thanks for this. I think you're right it would be a nicer API to return One possibility to keep it backwards compatible is to add a _raise = object() # unique object to signal a "raise exception" default
...
def get(self, key, default=_raise) -> str:
"""Fetch a snap configuration value.
Args:
key: the key to retrieve
default: if specified, return that value if the configuration key is not found
(the default is to raise SnapError)
Raises:
SnapError: if default not provided and the configuration key is not found
"""
if default is _raise:
return self._snap("get", [key]).strip()
else:
try:
return self._snap("get", [key]).strip()
except SnapError:
return default |
Hi @benhoyt my apologies for missing this message - that implementation sounds perfect thank you! |
Ben is out for a couple of weeks - @MiaAltieri are you able to get a PR together and we can get it through review? |
Problem
When performing snap get:
this will cause an error if
monitor-uri
is not setIdeal usage
Current usage
Desired Behavior
Return
None
if value is not setThe text was updated successfully, but these errors were encountered: