Skip to content

Commit 122977a

Browse files
committed
Clean up displaying errors when fetching build scans
Previously, if a build scan failed to fetch, then the error would be printed on the same line as the "Fetching build scan data" line, which was messy and harder to read. Now, error messages are gaurenteed to be on their own newline. Before: ``` Fetching build scan dataERROR: Failed to authenticate while attempting to fetch build scan https://example.com/s/jfg3vjxcgr3t2. ERROR: Failed to authenticate while attempting to fetch build scan https://example.com/s/wn43gciypu5j4. , done. ``` After: ``` Fetching build scan data ERROR: Failed to authenticate while attempting to fetch build scan https://example.com/s/sn6yisoolyoeu. ERROR: Failed to authenticate while attempting to fetch build scan https://example.com/s/v4q6wqny4rvvm. done. ```
1 parent fdc760d commit 122977a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

components/fetch-build-scan-data-cmdline-tool/src/main/java/com/gradle/enterprise/cli/ConsoleLogger.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class ConsoleLogger {
99
private final CommandLine.Help.ColorScheme colorScheme;
1010
private final boolean debugEnabled;
1111

12+
private boolean lastStatementIncludedNewline = true;
13+
1214
public ConsoleLogger(PrintStream out, CommandLine.Help.ColorScheme colorScheme, boolean debugEnabled) {
1315
this.out = out;
1416
this.colorScheme = colorScheme;
@@ -17,14 +19,16 @@ public ConsoleLogger(PrintStream out, CommandLine.Help.ColorScheme colorScheme,
1719

1820
public void info(String message) {
1921
out.println(message);
22+
lastStatementIncludedNewline = true;
2023
}
2124

2225
public void infoNoNewline(String message) {
2326
out.print(message);
27+
lastStatementIncludedNewline = false;
2428
}
2529

2630
public void info(String message, Object... args) {
27-
out.printf(message, args);
31+
info(String.format(message + "%n", args));
2832
}
2933

3034
public void debug(String message, Object... args) {
@@ -34,6 +38,7 @@ public void debug(String message, Object... args) {
3438
public void debug(String message) {
3539
if (debugEnabled) {
3640
out.println(colorScheme.text("@|faint " + message + "|@"));
41+
lastStatementIncludedNewline = true;
3742
}
3843
}
3944

@@ -46,7 +51,11 @@ public void error(String message, Object... args) {
4651
}
4752

4853
public void error(String message) {
54+
if (!lastStatementIncludedNewline) {
55+
out.println();
56+
}
4957
out.println(colorScheme.errorText(message));
58+
lastStatementIncludedNewline = true;
5059
}
5160

5261
public void error(Throwable t) {

components/fetch-build-scan-data-cmdline-tool/src/main/java/com/gradle/enterprise/cli/FetchBuildValidationDataCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static class ExitCode {
5454
@Option(names = {"--brief-logging"}, description = "Only log a short message about fetching build scan data and when it completes.")
5555
private boolean briefLogging;
5656

57+
private boolean someScansFailedToFetch = false;
58+
5759
@Override
5860
public Integer call() throws Exception {
5961
// Use System.err for logging since we're going to write out the CSV to System.out
@@ -108,6 +110,7 @@ private BuildValidationData fetchBuildScanData(int index, URL buildScanUrl, Cust
108110
}
109111

110112
private void printException(RuntimeException e) {
113+
someScansFailedToFetch = true;
111114
if (logger.isDebugEnabled()) {
112115
logger.error(e);
113116
if (e instanceof FailedRequestException) {
@@ -174,7 +177,7 @@ private void logStartFetchingBuildScans() {
174177

175178
private void logFinishedFetchingBuildScans() {
176179
if (briefLogging) {
177-
if (logger.isDebugEnabled()) {
180+
if (logger.isDebugEnabled() || someScansFailedToFetch) {
178181
logger.info("done.");
179182
} else {
180183
logger.info(", done.");
@@ -184,7 +187,7 @@ private void logFinishedFetchingBuildScans() {
184187

185188
private void logFinishedFetchingBuildScan() {
186189
if (!briefLogging) {
187-
if (logger.isDebugEnabled()) {
190+
if (logger.isDebugEnabled() || someScansFailedToFetch) {
188191
logger.info("done.");
189192
} else {
190193
logger.info(", done.");
@@ -223,7 +226,7 @@ private void logFetchResults(List<BuildValidationData> buildValidationData, Cust
223226

224227
private void logFetchResultFor(int index, String property, String customValueKey, boolean found) {
225228
String ordinal = buildScanIndexToOrdinal(index);
226-
logger.info("Looking up %s from custom value with name '%s' from the %s build scan, %s.%n", property, customValueKey, ordinal, found ? "found": "not found");
229+
logger.info("Looking up %s from custom value with name '%s' from the %s build scan, %s.", property, customValueKey, ordinal, found ? "found": "not found");
227230
}
228231

229232
public void printHeader() {

0 commit comments

Comments
 (0)