Skip to content

Commit 6e04c32

Browse files
Bubble up more descriptive logs from GitHub when enqueuing a PR fails. (#5017)
GitHub does provide useful and descriptive messages when there is some issue with enqueuing the PR into the merge queue. Unfortunately, right now we're just saying `400 GraphQL mutate failed` which doesn't help the user figure out how to unblock their PR. This change adds the info from the GitHub response in to the message.
1 parent f20d3ad commit 6e04c32

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

auto_submit/lib/service/graphql_service.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ class GraphQlService {
4646

4747
if (queryResult.hasException) {
4848
log.error('GraphQL query failed', queryResult.exception);
49-
throw const BadRequestException('GraphQL query failed');
49+
final exception = queryResult.exception!;
50+
final errors = exception.graphqlErrors;
51+
String errorMessage;
52+
if (errors.isNotEmpty) {
53+
errorMessage = errors.map((e) => e.message).join(', ');
54+
} else if (exception.linkException != null) {
55+
errorMessage = exception.linkException.toString();
56+
} else {
57+
errorMessage = 'GraphQL query failed';
58+
}
59+
throw BadRequestException(errorMessage);
5060
}
5161
return queryResult.data!;
5262
}
@@ -67,7 +77,17 @@ class GraphQlService {
6777

6878
if (queryResult.hasException) {
6979
log.error('GraphQL mutate failed', queryResult.exception);
70-
throw const BadRequestException('GraphQL mutate failed');
80+
final exception = queryResult.exception!;
81+
final errors = exception.graphqlErrors;
82+
String errorMessage;
83+
if (errors.isNotEmpty) {
84+
errorMessage = errors.map((e) => e.message).join(', ');
85+
} else if (exception.linkException != null) {
86+
errorMessage = exception.linkException.toString();
87+
} else {
88+
errorMessage = 'GraphQL mutate failed';
89+
}
90+
throw BadRequestException(errorMessage);
7191
}
7292
return queryResult.data!;
7393
}

auto_submit/test/service/pull_request_validation_service_test.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,14 @@ This is the second line in a paragraph.''');
627627
return QueryResult(
628628
options: options,
629629
source: QueryResultSource.network,
630-
exception: OperationException(),
630+
exception: OperationException(
631+
graphqlErrors: <GraphQLError>[
632+
const GraphQLError(
633+
message:
634+
'Pull request New changes require approval from someone other than Piinks because they were the last pusher.',
635+
),
636+
],
637+
),
631638
);
632639
};
633640

@@ -648,7 +655,7 @@ This is the second line in a paragraph.''');
648655
expect(
649656
result.message,
650657
contains(
651-
'Failed to enqueue flutter/flutter/42 with HTTP 400: GraphQL mutate failed',
658+
'Failed to enqueue flutter/flutter/42 with HTTP 400: Pull request New changes require approval from someone other than Piinks because they were the last pusher.',
652659
),
653660
);
654661
});

0 commit comments

Comments
 (0)