Skip to content

Commit ab336e6

Browse files
committed
better errors
1 parent 05613b4 commit ab336e6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

googleapis_auth/lib/src/adc_utils.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ Future<AutoRefreshingAuthClient> fromApplicationsCredentialsFile(
2727
Object? credentials;
2828
try {
2929
credentials = json.decode(await file.readAsString());
30-
} on IOException {
30+
} on IOException catch (e) {
3131
throw CredentialsFileException(
3232
'Failed to read credentials file from $fileSource',
33+
e,
3334
);
34-
} on FormatException {
35+
} on FormatException catch (e) {
3536
throw CredentialsFileException(
3637
'Failed to parse JSON from credentials file from $fileSource',
38+
e,
3739
);
3840
}
3941

googleapis_auth/lib/src/exceptions.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ class ServerRequestFailedException implements Exception {
6060
/// Thrown when an error occurs reading or parsing a credentials file.
6161
class CredentialsFileException implements Exception {
6262
final String message;
63+
final Object? innerError;
6364

64-
const CredentialsFileException(this.message);
65+
const CredentialsFileException(this.message, [this.innerError]);
6566

6667
@override
67-
String toString() => 'CredentialsFileException: $message';
68+
String toString() => [
69+
'CredentialsFileException: $message',
70+
if (innerError != null) '($innerError)',
71+
].join(' ');
6872
}
6973

7074
/// Thrown when the oauth2 callback request from the authorization server is

0 commit comments

Comments
 (0)