-
Notifications
You must be signed in to change notification settings - Fork 383
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
Improve error messages when loading credentials. #1212
Improve error messages when loading credentials. #1212
Conversation
This fixes googleapis#974. The error messages when loading an invalid or missing credentials file were sometimes very obscure (typically some parsing problem in the JSON library). The new error messages should make it easier to diagnose the problem.
Codecov Report
@@ Coverage Diff @@
## master #1212 +/- ##
==========================================
+ Coverage 92.2% 92.23% +0.03%
==========================================
Files 224 226 +2
Lines 12313 12370 +57
==========================================
+ Hits 11353 11410 +57
Misses 960 960
Continue to review full report at Codecov.
|
char const REFRESH_TOKEN_KEY[] = "refresh_token"; | ||
for (auto const& key : | ||
{CLIENT_ID_KEY, CLIENT_SECRET_KEY, REFRESH_TOKEN_KEY}) { | ||
if (credentials.count(key) == 0U) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this new logic could be factored out into its own function, which would (probably) make testing it easier. If you had something like ParseAndValidateCredentialContent()
, it could check if the content is valid/parseable JSON, check that the required fields exist, and make sure that those fields aren't empty (meaning we don't have to change the .get()
calls below)... returning the nl::json object if all went well, or raising/dying at the first error it finds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored, let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This fixes #974. The error messages when loading an invalid or missing
credentials file were sometimes very obscure (typically some parsing
problem in the JSON library). The new error messages should make it
easier to diagnose the problem.
This change is