add additional console logging (#59)
* add additional console logging
* also print headers
diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md
index e71f5bf..14a07a3 100644
--- a/pkgs/firehose/CHANGELOG.md
+++ b/pkgs/firehose/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.3.11
+
+- Add additional console logging when we encounter GitHub API errors.
+
## 0.3.10
- Fixed an exception that occurred when no CHANGELOG.md file was present.
diff --git a/pkgs/firehose/lib/firehose.dart b/pkgs/firehose/lib/firehose.dart
index 22cad5a..f187c75 100644
--- a/pkgs/firehose/lib/firehose.dart
+++ b/pkgs/firehose/lib/firehose.dart
@@ -29,7 +29,7 @@
/// - provide feedback on the PR (via a PR comment) about packages which are
/// ready to publish
Future<void> validate() async {
- var github = Github();
+ var github = Github(verbose: true);
// Do basic validation of our expected env var.
if (!_expectEnv(github.githubAuthToken, 'GITHUB_TOKEN')) return;
@@ -285,7 +285,12 @@
Result(Severity.success, package, message, other);
@override
- String toString() => severity == Severity.error ? 'error: $message' : message;
+ String toString() {
+ final details = other == null ? '' : ' ($other)';
+ return severity == Severity.error
+ ? 'error: $message$details'
+ : '$message$details';
+ }
}
enum Severity {
diff --git a/pkgs/firehose/lib/src/github.dart b/pkgs/firehose/lib/src/github.dart
index 7ed7900..265595c 100644
--- a/pkgs/firehose/lib/src/github.dart
+++ b/pkgs/firehose/lib/src/github.dart
@@ -12,8 +12,13 @@
class Github {
static Map<String, String> get _env => Platform.environment;
+ /// When true, details of any RPC error are printed to the console.
+ final bool verbose;
+
http.Client? _httpClient;
+ Github({this.verbose = false});
+
String? get githubAuthToken => _env['GITHUB_TOKEN'];
/// The owner and repository name. For example, `octocat/Hello-World`.
@@ -62,9 +67,17 @@
},
body: body)
.then((response) {
- return response.statusCode != 201
- ? throw RpcException(response.reasonPhrase!)
- : response.body;
+ if (response.statusCode != 201) {
+ if (verbose) {
+ stderr.writeln('${response.statusCode} ${response.reasonPhrase}');
+ for (var entry in response.headers.entries) {
+ stderr.writeln('${entry.key}: ${entry.value}');
+ }
+ stderr.writeln(response.body);
+ }
+ throw RpcException(response.reasonPhrase!);
+ }
+ return response.body;
});
}
diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml
index 88555a6..b36f49d 100644
--- a/pkgs/firehose/pubspec.yaml
+++ b/pkgs/firehose/pubspec.yaml
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
-version: 0.3.10
+version: 0.3.11
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose
environment: