Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Fix error handler. #631

Merged
merged 6 commits into from
Sep 11, 2017
Merged

Fix error handler. #631

merged 6 commits into from
Sep 11, 2017

Conversation

blueandgold
Copy link
Contributor

@blueandgold blueandgold commented Sep 8, 2017

This properly handles the error when the admin directory api client can not be created due to missing gsuite key, so that we can get the proper logging message to understand what happened.

2017-09-08 16:29:11,241 google.cloud.security.inventory.pipeline_builder ERROR    _get_api Failed to initialize API AdminDirectoryClient, v=None
('Error building admin api credential: %s', IOError(2, 'No such file or directory'))

@ahoying, AFAICT, this will not affect the rest of the api clients. Can you please confirm?

@codecov
Copy link

codecov bot commented Sep 9, 2017

Codecov Report

Merging #631 into dev will not change coverage.
The diff coverage is 0%.

@@           Coverage Diff           @@
##              dev     #631   +/-   ##
=======================================
  Coverage   83.33%   83.33%           
=======================================
  Files         164      164           
  Lines        8109     8109           
=======================================
  Hits         6758     6758           
  Misses       1351     1351
Impacted Files Coverage Δ
...oogle/cloud/security/inventory/pipeline_builder.py 79.38% <0%> (ø) ⬆️

except api_errors.ApiExecutionError as e:
LOGGER.error('Failed to execute API %s, v=%s\n%s',
except api_errors.ApiInitializationError as e:
LOGGER.error('Failed to initialize API %s, v=%s\n%s',
api_class_name, api_version, e)
raise api_errors.ApiInitializationError(e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just be the following, since you are re-raising the same exception now:

raise

@@ -90,8 +90,8 @@ def _get_api(self, api_name):
else:
api = api_class(self.global_configs,
version=api_version)
except api_errors.ApiExecutionError as e:
LOGGER.error('Failed to execute API %s, v=%s\n%s',
except api_errors.ApiInitializationError as e:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should have an except for both ApiExecutionError and ApiInitializationError. That way you can recover or propagate either type of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would do it, but at this point, we really are just initializing the api clients and not executing them. Can you please confirm if this is still what would be nice to do?

Changed the raise statement to just a single raise.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So long as that's the only exception that we care about at this stage and we know we've consistently made sure that's the exception that is raised, then that makes sense. I think longer term there is a lot more work to do around exception handling and ensuring all APIs are consistent. I tried to make things more consistent in my mixins PR, but I know more work needs to be done.

Copy link
Contributor Author

@blueandgold blueandgold left a comment

Choose a reason for hiding this comment

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

Thanks for the review. PTAL

@@ -90,8 +90,8 @@ def _get_api(self, api_name):
else:
api = api_class(self.global_configs,
version=api_version)
except api_errors.ApiExecutionError as e:
LOGGER.error('Failed to execute API %s, v=%s\n%s',
except api_errors.ApiInitializationError as e:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would do it, but at this point, we really are just initializing the api clients and not executing them. Can you please confirm if this is still what would be nice to do?

Changed the raise statement to just a single raise.

@blueandgold blueandgold merged commit b8d27d9 into dev Sep 11, 2017
@blueandgold blueandgold deleted the fixerrorhandler branch September 12, 2017 04:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants