diff --git a/auto_submit/lib/request_handling/pubsub.dart b/auto_submit/lib/request_handling/pubsub.dart index 1ddcc6a3b6..40ce8f7f6d 100644 --- a/auto_submit/lib/request_handling/pubsub.dart +++ b/auto_submit/lib/request_handling/pubsub.dart @@ -59,15 +59,21 @@ class PubSub { /// /// The PubSub system can remove the relevant messages from the subscription. Future acknowledge(String subscription, String ackId) async { - final Client httpClient = await clientViaApplicationDefaultCredentials( - scopes: [pubsub.PubsubApi.pubsubScope], - ); - final pubsubApi = pubsub.PubsubApi(httpClient); - final ackIds = [ackId]; - final acknowledgeRequest = pubsub.AcknowledgeRequest(ackIds: ackIds); - await pubsubApi.projects.subscriptions.acknowledge( - acknowledgeRequest, - '${Config.pubsubSubscriptionsPrefix}/$subscription', - ); + try { + final Client httpClient = await clientViaApplicationDefaultCredentials( + scopes: [pubsub.PubsubApi.pubsubScope], + ); + final pubsubApi = pubsub.PubsubApi(httpClient); + final ackIds = [ackId]; + final acknowledgeRequest = pubsub.AcknowledgeRequest(ackIds: ackIds); + await pubsubApi.projects.subscriptions.acknowledge( + acknowledgeRequest, + '${Config.pubsubSubscriptionsPrefix}/$subscription', + ); + } catch (e) { + log.error( + 'Failed to acknowledge message $ackId for subscription $subscription: $e', + ); + } } } diff --git a/auto_submit/test/request_handling/pubsub_test.dart b/auto_submit/test/request_handling/pubsub_test.dart new file mode 100644 index 0000000000..db292200e3 --- /dev/null +++ b/auto_submit/test/request_handling/pubsub_test.dart @@ -0,0 +1,19 @@ +// Copyright 2026 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:auto_submit/request_handling/pubsub.dart'; +import 'package:test/test.dart'; + +void main() { + group('PubSub', () { + test('acknowledge handles exceptions gracefully', () async { + const pubsub = PubSub(); + // This should not throw even if credentials are missing or API fails. + await expectLater( + pubsub.acknowledge('test-sub', 'test-ack-id'), + completes, + ); + }); + }); +}