diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerAccountsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerAccountsService.kt index a7b037b6f2d..5f033a164fd 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerAccountsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerAccountsService.kt @@ -73,13 +73,14 @@ class SpannerAccountsService( ) .execute(client, idGenerator) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Creator's Account not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Creator's Account not found.") } catch (e: PermissionDeniedException) { - e.throwStatusRuntimeException(Status.PERMISSION_DENIED) { + throw e.asStatusRuntimeException( + Status.Code.PERMISSION_DENIED, "Caller does not own the owned measurement consumer." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -102,21 +103,27 @@ class SpannerAccountsService( ) .execute(client, idGenerator) } catch (e: PermissionDeniedException) { - e.throwStatusRuntimeException(Status.PERMISSION_DENIED) { + throw e.asStatusRuntimeException( + Status.Code.PERMISSION_DENIED, "Activation token is not valid for this account." - } + ) } catch (e: DuplicateAccountIdentityException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Issuer and subject pair already exists." - } + ) } catch (e: AccountActivationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Cannot activate an account again. " - } + ) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Account to activate has not been found." } + throw e.asStatusRuntimeException( + Status.Code.NOT_FOUND, + "Account to activate has not been found." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } @@ -129,17 +136,19 @@ class SpannerAccountsService( ) .execute(client, idGenerator) } catch (e: DuplicateAccountIdentityException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Issuer and subject pair already exists." - } + ) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Account was not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Account was not found.") } catch (e: AccountActivationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Account has not been activated yet." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerApiKeysService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerApiKeysService.kt index c5776832fe7..e4d6d35be91 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerApiKeysService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerApiKeysService.kt @@ -40,9 +40,9 @@ class SpannerApiKeysService( try { return CreateApiKey(request).execute(client, idGenerator) } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } @@ -54,11 +54,11 @@ class SpannerApiKeysService( ) .execute(client, idGenerator) } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: ApiKeyNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Api Key not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Api Key not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerCertificatesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerCertificatesService.kt index 03ddc1eca80..250a6f3f1ba 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerCertificatesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerCertificatesService.kt @@ -56,19 +56,20 @@ class SpannerCertificatesService( try { return CreateCertificate(request).execute(client, idGenerator) } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement Consumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement Consumer not found.") } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Data Provider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Data Provider not found.") } catch (e: ModelProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Model Provider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Model Provider not found.") } catch (e: CertSubjectKeyIdAlreadyExistsException) { - e.throwStatusRuntimeException(Status.ALREADY_EXISTS) { + throw e.asStatusRuntimeException( + Status.Code.ALREADY_EXISTS, "Certificate with the subject key identifier (SKID) already exists." - } + ) } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } @@ -117,13 +118,16 @@ class SpannerCertificatesService( try { return RevokeCertificate(request).execute(client, idGenerator) } catch (e: CertificateNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Certificate not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Certificate not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.") } catch (e: CertificateRevocationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is in wrong State." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Certificate is in wrong State." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } @@ -134,13 +138,16 @@ class SpannerCertificatesService( try { return ReleaseCertificateHold(request).execute(client, idGenerator) } catch (e: CertificateNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Certificate not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Certificate not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.") } catch (e: CertificateRevocationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is in wrong State." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Certificate is in wrong State." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerComputationParticipantsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerComputationParticipantsService.kt index 90b3b372819..ed6413d1fd9 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerComputationParticipantsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerComputationParticipantsService.kt @@ -45,29 +45,38 @@ class SpannerComputationParticipantsService( try { return SetParticipantRequisitionParams(request).execute(client, idGenerator) } catch (e: ComputationParticipantStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "ComputationParticipant not in CREATED state." - } + ) } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Measurement not in PENDING_REQUISITION_PARAMS state." - } + ) } catch (e: ComputationParticipantNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: DuchyCertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy's Certificate not found." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Duchy's Certificate not found." + ) } catch (e: CertificateIsInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is invalid." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Certificate is invalid.") } catch (e: DuplicateAccountIdentityException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Account Identity duplicated." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Account Identity duplicated." + ) } catch (e: AccountActivationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Account activation state illegal." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -77,13 +86,16 @@ class SpannerComputationParticipantsService( try { return FailComputationParticipant(request).execute(client, idGenerator) } catch (e: ComputationParticipantNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement state is illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement state is illegal." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -93,17 +105,21 @@ class SpannerComputationParticipantsService( try { return ConfirmComputationParticipant(request).execute(client, idGenerator) } catch (e: ComputationParticipantNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.") } catch (e: ComputationParticipantStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "ComputationParticipant in illegal state." - } + ) } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement in illegal state." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement in illegal state." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerDataProvidersService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerDataProvidersService.kt index 051cb910097..032ca8d4e76 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerDataProvidersService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerDataProvidersService.kt @@ -58,7 +58,7 @@ class SpannerDataProvidersService( try { return ReplaceDataProviderRequiredDuchies(request).execute(client, idGenerator) } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupMetadataDescriptorsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupMetadataDescriptorsService.kt index fa40fd01e04..b72e632ea86 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupMetadataDescriptorsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupMetadataDescriptorsService.kt @@ -44,9 +44,9 @@ class SpannerEventGroupMetadataDescriptorsService( try { return CreateEventGroupMetadataDescriptor(request).execute(client, idGenerator) } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } @@ -76,9 +76,12 @@ class SpannerEventGroupMetadataDescriptorsService( return UpdateEventGroupMetadataDescriptor(request.eventGroupMetadataDescriptor) .execute(client, idGenerator) } catch (e: EventGroupMetadataDescriptorNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroupMetadataDescriptor not found." } + throw e.asStatusRuntimeException( + Status.Code.NOT_FOUND, + "EventGroupMetadataDescriptor not found." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupsService.kt index 766b844008c..c16d3f660c0 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerEventGroupsService.kt @@ -52,19 +52,24 @@ class SpannerEventGroupsService( try { return CreateEventGroup(request).execute(client, idGenerator) } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "MeasurementConsumer not found." + ) } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } catch (e: CertificateIsInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "MeasurementConsumer's Certificate is invalid." - } + ) } catch (e: MeasurementConsumerCertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "MeasurementConsumer's Certificate not found." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -76,30 +81,35 @@ class SpannerEventGroupsService( try { return UpdateEventGroup(request.eventGroup).execute(client, idGenerator) } catch (e: EventGroupInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, "EventGroup modification param is invalid." - } + ) } catch (e: CertificateIsInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "MeasurementConsumer's Certificate is invalid." - } + ) } catch (e: MeasurementConsumerCertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "MeasurementConsumer's Certificate not found." - } + ) } catch (e: EventGroupNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroup not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "EventGroup not found.") } catch (e: EventGroupStateIllegalException) { when (e.state) { - EventGroup.State.DELETED -> - e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroup state is DELETED." } + EventGroup.State.DELETED -> { + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "EventGroup state is DELETED.") + } EventGroup.State.ACTIVE, EventGroup.State.STATE_UNSPECIFIED, - EventGroup.State.UNRECOGNIZED -> - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + EventGroup.State.UNRECOGNIZED -> { + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") + } } } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -126,18 +136,20 @@ class SpannerEventGroupsService( try { return DeleteEventGroup(eventGroup).execute(client, idGenerator) } catch (e: EventGroupNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroup not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "EventGroup not found.") } catch (e: EventGroupStateIllegalException) { when (e.state) { - EventGroup.State.DELETED -> - e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroup state is DELETED." } + EventGroup.State.DELETED -> { + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "EventGroup state is DELETED.") + } EventGroup.State.ACTIVE, EventGroup.State.STATE_UNSPECIFIED, - EventGroup.State.UNRECOGNIZED -> - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + EventGroup.State.UNRECOGNIZED -> { + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") + } } } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangeStepAttemptsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangeStepAttemptsService.kt index dd30dbca037..be13ee62c11 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangeStepAttemptsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangeStepAttemptsService.kt @@ -98,13 +98,13 @@ class SpannerExchangeStepAttemptsService( } .execute(client.singleUse()) .singleOrNull() - ?: ExchangeStepAttemptNotFoundException( + ?: throw ExchangeStepAttemptNotFoundException( externalRecurringExchangeId, request.date, request.stepIndex, request.attemptNumber ) - .throwStatusRuntimeException(Status.NOT_FOUND) + .asStatusRuntimeException(Status.Code.NOT_FOUND) return result.exchangeStepAttempt } @@ -126,11 +126,11 @@ class SpannerExchangeStepAttemptsService( try { return writer.execute(client, idGenerator) } catch (e: RecurringExchangeNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND) } catch (e: ExchangeStepNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND) } catch (e: ExchangeStepAttemptNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangesService.kt index d3f3f4a1a9a..79ed79af8cd 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerExchangesService.kt @@ -87,9 +87,9 @@ class SpannerExchangesService( try { return BatchDeleteExchanges(request).execute(client, idGenerator) } catch (e: ExchangeNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Exchange not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Exchange not found") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementConsumersService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementConsumersService.kt index 822b384fb80..0a4402d4ef0 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementConsumersService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementConsumersService.kt @@ -59,17 +59,19 @@ class SpannerMeasurementConsumersService( ) .execute(client, idGenerator) } catch (e: PermissionDeniedException) { - e.throwStatusRuntimeException(Status.PERMISSION_DENIED) { + throw e.asStatusRuntimeException( + Status.Code.PERMISSION_DENIED, "Measurement Consumer creation token is not valid." - } + ) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Account not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Account not found.") } catch (e: AccountActivationStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Account has not been activated yet." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -95,11 +97,11 @@ class SpannerMeasurementConsumersService( ) .execute(client, idGenerator) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Account not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Account not found.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -113,15 +115,16 @@ class SpannerMeasurementConsumersService( ) .execute(client, idGenerator) } catch (e: AccountNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Account not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Account not found.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: PermissionDeniedException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Account doesn't own MeasurementConsumer." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementLogEntriesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementLogEntriesService.kt index 7a435730439..010024bb0c2 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementLogEntriesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementLogEntriesService.kt @@ -52,13 +52,16 @@ class SpannerMeasurementLogEntriesService( try { return CreateDuchyMeasurementLogEntry(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement in wrong state." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement in wrong state." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementsService.kt index 81ea7701cf9..4482d4a3ca1 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerMeasurementsService.kt @@ -66,19 +66,19 @@ class SpannerMeasurementsService( try { return CreateMeasurement(request).execute(client, idGenerator) } catch (e: CertificateIsInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is invalid." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Certificate is invalid.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "DataProvider not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: CertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Certificate not found.") } catch (e: DuchyNotActiveException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Inactive required duchy." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Inactive required duchy.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -139,15 +139,16 @@ class SpannerMeasurementsService( try { return SetMeasurementResult(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: DuchyCertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Aggregator's Certificate not found." - } + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -166,11 +167,14 @@ class SpannerMeasurementsService( return CancelMeasurement(externalMeasurementConsumerId, externalMeasurementId) .execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement state illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement state illegal." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -179,11 +183,11 @@ class SpannerMeasurementsService( try { return BatchDeleteMeasurements(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: MeasurementEtagMismatchException) { - e.throwStatusRuntimeException(Status.ABORTED) { "Measurement etag mismatch." } + throw e.asStatusRuntimeException(Status.Code.ABORTED, "Measurement etag mismatch.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -208,11 +212,11 @@ class SpannerMeasurementsService( try { return BatchCancelMeasurements(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: MeasurementEtagMismatchException) { - e.throwStatusRuntimeException(Status.ABORTED) { "Measurement etag mismatch." } + throw e.asStatusRuntimeException(Status.Code.ABORTED, "Measurement etag mismatch.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelLinesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelLinesService.kt index d2d79a6048f..48cd61cf4f1 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelLinesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelLinesService.kt @@ -52,16 +52,18 @@ class SpannerModelLinesService( try { return CreateModelLine(request, clock).execute(client, idGenerator) } catch (e: ModelSuiteNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelSuite not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelSuite not found.") } catch (e: ModelLineTypeIllegalException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, e.message ?: "Only ModelLines with type equal to 'PROD' can have a HoldbackModelLine having type equal to 'HOLDBACK'." - } + ) } catch (e: ModelLineInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, e.message ?: "ActiveStartTime and/or ActiveEndTime is invalid." - } + ) } } @@ -70,11 +72,12 @@ class SpannerModelLinesService( try { return SetActiveEndTime(request, clock).execute(client, idGenerator) } catch (e: ModelLineNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelLine not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelLine not found.") } catch (e: ModelLineInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, e.message ?: "ModelLine invalid active time argument." - } + ) } } @@ -124,12 +127,13 @@ class SpannerModelLinesService( try { return SetModelLineHoldbackModelLine(request).execute(client, idGenerator) } catch (e: ModelLineNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { e.message ?: "ModelLine not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, e.message ?: "ModelLine not found.") } catch (e: ModelLineTypeIllegalException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, e.message ?: "Only ModelLines with type equal to 'PROD' can have a HoldbackModelLine having type equal to 'HOLDBACK'." - } + ) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelOutagesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelOutagesService.kt index 3990b7dfa1a..38939083126 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelOutagesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelOutagesService.kt @@ -49,11 +49,12 @@ class SpannerModelOutagesService( try { return CreateModelOutage(request).execute(client, idGenerator) } catch (e: ModelLineNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelLine not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelLine not found.") } catch (e: ModelOutageInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, e.message ?: "ModelOutageStartTime cannot precede ModelOutageEndTime." - } + ) } } @@ -73,18 +74,20 @@ class SpannerModelOutagesService( try { return DeleteModelOutage(modelOutage).execute(client, idGenerator) } catch (e: ModelOutageNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelOutage not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelOutage not found.") } catch (e: ModelOutageStateIllegalException) { when (e.state) { - ModelOutage.State.DELETED -> - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelOutage state is DELETED." } + ModelOutage.State.DELETED -> { + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelOutage state is DELETED.") + } ModelOutage.State.ACTIVE, ModelOutage.State.STATE_UNSPECIFIED, - ModelOutage.State.UNRECOGNIZED -> - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + ModelOutage.State.UNRECOGNIZED -> { + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") + } } } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelReleasesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelReleasesService.kt index ba0e98f315b..ae623acf1e8 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelReleasesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelReleasesService.kt @@ -42,7 +42,7 @@ class SpannerModelReleasesService( try { return CreateModelRelease(request).execute(client, idGenerator) } catch (e: ModelSuiteNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelSuite not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelSuite not found.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelRolloutsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelRolloutsService.kt index 28642c07097..cbd96ed9521 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelRolloutsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelRolloutsService.kt @@ -57,11 +57,11 @@ class SpannerModelRolloutsService( try { return CreateModelRollout(request, clock).execute(client, idGenerator) } catch (e: ModelRolloutInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) + throw e.asStatusRuntimeException(Status.Code.INVALID_ARGUMENT) } catch (e: ModelLineNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelLine not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelLine not found.") } catch (e: ModelReleaseNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelRelease not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelRelease not found.") } } @@ -74,9 +74,9 @@ class SpannerModelRolloutsService( try { return ScheduleModelRolloutFreeze(request, clock).execute(client, idGenerator) } catch (e: ModelRolloutInvalidArgsException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) + throw e.asStatusRuntimeException(Status.Code.INVALID_ARGUMENT) } catch (e: ModelRolloutNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelRollout not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelRollout not found.") } } @@ -120,11 +120,12 @@ class SpannerModelRolloutsService( try { return DeleteModelRollout(request, clock).execute(client, idGenerator) } catch (e: ModelRolloutNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelRollout not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelRollout not found.") } catch (e: ModelRolloutInvalidArgsException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "RolloutStartTime already passed" - } + ) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelShardsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelShardsService.kt index ae785923667..dffd38fbd89 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelShardsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelShardsService.kt @@ -49,11 +49,11 @@ class SpannerModelShardsService( try { return CreateModelShard(request).execute(client, idGenerator) } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } catch (e: ModelSuiteNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelSuite not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelSuite not found.") } catch (e: ModelReleaseNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelRelease not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelRelease not found.") } } @@ -67,11 +67,11 @@ class SpannerModelShardsService( ) .execute(client, idGenerator) } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } catch (e: ModelShardNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelShard not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelShard not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelSuitesService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelSuitesService.kt index de1cd0f9725..39b44d7baf0 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelSuitesService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerModelSuitesService.kt @@ -43,7 +43,7 @@ class SpannerModelSuitesService( try { return CreateModelSuite(request).execute(client, idGenerator) } catch (e: ModelProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "ModelProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ModelProvider not found.") } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerPublicKeysService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerPublicKeysService.kt index c031ac2bb6b..ec29590cec7 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerPublicKeysService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerPublicKeysService.kt @@ -51,13 +51,13 @@ class SpannerPublicKeysService( UpdatePublicKey(request).execute(client, idGenerator) return updatePublicKeyResponse {} } catch (e: CertificateNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Certificate not found.") } catch (e: DataProviderNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerRequisitionsService.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerRequisitionsService.kt index e9f0796da87..2658edbc9ad 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerRequisitionsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/SpannerRequisitionsService.kt @@ -95,15 +95,21 @@ class SpannerRequisitionsService( try { return FulfillRequisition(request).execute(client, idGenerator) } catch (e: RequisitionNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Requisition not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Requisition not found.") } catch (e: RequisitionStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Requisition state illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Requisition state illegal." + ) } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement state illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement state illegal." + ) } catch (e: DuchyNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." } + throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.") } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } @@ -122,13 +128,19 @@ class SpannerRequisitionsService( try { return RefuseRequisition(request).execute(client, idGenerator) } catch (e: RequisitionNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Requisition not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Requisition not found.") } catch (e: RequisitionStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Requisition state illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Requisition state illegal." + ) } catch (e: MeasurementStateIllegalException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement state illegal." } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement state illegal." + ) } catch (e: KingdomInternalException) { - e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." } + throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.") } } } diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/BUILD.bazel index e96379f3d3a..d3d86257313 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/BUILD.bazel @@ -10,6 +10,8 @@ kt_jvm_library( srcs = glob(["*.kt"]), deps = [ "//src/main/kotlin/org/wfanet/measurement/common/identity", + "//src/main/proto/google/rpc:error_details_kt_jvm_proto", + "//src/main/proto/google/rpc:status_kt_jvm_proto", "//src/main/proto/wfa/measurement/internal/common:provider_kt_jvm_proto", "//src/main/proto/wfa/measurement/internal/kingdom:account_kt_jvm_proto", "//src/main/proto/wfa/measurement/internal/kingdom:certificate_kt_jvm_proto", diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/KingdomInternalException.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/KingdomInternalException.kt index 69c67f93983..6b5d521c357 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/KingdomInternalException.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/deploy/gcloud/spanner/common/KingdomInternalException.kt @@ -14,11 +14,13 @@ package org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common +import com.google.protobuf.Any import com.google.rpc.errorInfo +import com.google.rpc.status import com.google.type.Date -import io.grpc.Metadata import io.grpc.Status -import io.grpc.protobuf.ProtoUtils +import io.grpc.StatusRuntimeException +import io.grpc.protobuf.StatusProto import org.wfanet.measurement.common.identity.ExternalId import org.wfanet.measurement.common.identity.InternalId import org.wfanet.measurement.internal.kingdom.Account @@ -43,20 +45,27 @@ sealed class KingdomInternalException : Exception { this.code = code } - fun throwStatusRuntimeException( - status: Status = Status.INVALID_ARGUMENT, - provideDescription: () -> String = { message ?: "" }, - ): Nothing { - val info = errorInfo { - reason = code.toString() - domain = ErrorCode.getDescriptor().fullName - metadata.putAll(context) + fun asStatusRuntimeException( + statusCode: Status.Code, + message: String = this.message!! + ): StatusRuntimeException { + val statusProto = status { + code = statusCode.value() + this.message = message + details += + Any.pack( + errorInfo { + reason = this@KingdomInternalException.code.toString() + domain = ErrorCode.getDescriptor().fullName + metadata.putAll(context) + } + ) } - val metadata = Metadata() - metadata.put(ProtoUtils.keyForProto(info), info) - - throw status.withDescription(provideDescription()).asRuntimeException(metadata) + // Unpack exception to add cause. + // TODO(grpc/grpc-java#10230): Use new API when available. + val exception = StatusProto.toStatusRuntimeException(statusProto) + return exception.status.withCause(this).asRuntimeException(exception.trailers) } override fun toString(): String { diff --git a/src/main/kotlin/org/wfanet/measurement/kingdom/service/internal/testing/Population.kt b/src/main/kotlin/org/wfanet/measurement/kingdom/service/internal/testing/Population.kt index fb08c0e1521..320728625bb 100644 --- a/src/main/kotlin/org/wfanet/measurement/kingdom/service/internal/testing/Population.kt +++ b/src/main/kotlin/org/wfanet/measurement/kingdom/service/internal/testing/Population.kt @@ -15,10 +15,11 @@ package org.wfanet.measurement.kingdom.service.internal.testing import com.google.gson.JsonParser +import com.google.protobuf.Any import com.google.protobuf.kotlin.toByteStringUtf8 import com.google.rpc.ErrorInfo import io.grpc.StatusRuntimeException -import io.grpc.protobuf.ProtoUtils +import io.grpc.protobuf.StatusProto import java.time.Clock import java.time.Instant import java.time.temporal.ChronoUnit @@ -423,12 +424,16 @@ fun DataProvider.toDataProviderValue(nonce: Long = Random.Default.nextLong()) = } /** - * [ErrorInfo] from [trailers][StatusRuntimeException.getTrailers]. + * [ErrorInfo] from status details. * * TODO(@SanjayVas): Move this to common.grpc. */ val StatusRuntimeException.errorInfo: ErrorInfo? get() { - val key = ProtoUtils.keyForProto(ErrorInfo.getDefaultInstance()) - return trailers?.get(key) + val errorInfoFullName = ErrorInfo.getDescriptor().fullName + val statusProto: com.google.rpc.Status = StatusProto.fromStatusAndTrailers(status, trailers) + val errorInfoPacked: Any = + statusProto.detailsList.find { it.typeUrl.endsWith("/$errorInfoFullName") } ?: return null + + return errorInfoPacked.unpack(ErrorInfo::class.java) } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsService.kt index 9b20b769ec5..b85aabc9fd6 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresMeasurementsService.kt @@ -39,7 +39,7 @@ class PostgresMeasurementsService( return try { CreateMeasurement(request).execute(client, idGenerator) } catch (e: MeasurementAlreadyExistsException) { - e.throwStatusRuntimeException(Status.ALREADY_EXISTS) { "Measurement already exists." } + throw e.asStatusRuntimeException(Status.Code.ALREADY_EXISTS, "Measurement already exists.") } } @@ -53,9 +53,8 @@ class PostgresMeasurementsService( request.measurementReferenceId ) } - ?: MeasurementNotFoundException().throwStatusRuntimeException(Status.NOT_FOUND) { - "Measurement not found." - } + ?: throw MeasurementNotFoundException() + .asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") return measurementResult.measurement } @@ -64,11 +63,12 @@ class PostgresMeasurementsService( return try { SetMeasurementResult(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: MeasurementStateInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Measurement has already been updated." - } + ) } } @@ -76,11 +76,12 @@ class PostgresMeasurementsService( return try { SetMeasurementFailure(request).execute(client, idGenerator) } catch (e: MeasurementNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement not found.") } catch (e: MeasurementStateInvalidException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Measurement has already been updated." - } + ) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsService.kt index 9b9f2f0e4e0..7b7a70c8874 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportingSetsService.kt @@ -40,9 +40,10 @@ class PostgresReportingSetsService( return try { CreateReportingSet(request).execute(client, idGenerator) } catch (e: ReportingSetAlreadyExistsException) { - e.throwStatusRuntimeException(Status.ALREADY_EXISTS) { + throw e.asStatusRuntimeException( + Status.Code.ALREADY_EXISTS, "IDs generated for Reporting Set already exist" - } + ) } } @@ -58,7 +59,7 @@ class PostgresReportingSetsService( .reportingSet } } catch (e: ReportingSetNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Reporting Set not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Reporting Set not found") } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportsService.kt index e3c05e99a82..4de9aeee257 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/postgres/PostgresReportsService.kt @@ -41,11 +41,12 @@ class PostgresReportsService( try { return CreateReport(request).execute(client, idGenerator) } catch (e: ReportingSetNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Reporting Set not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Reporting Set not found") } catch (e: MeasurementCalculationTimeIntervalNotFoundException) { - e.throwStatusRuntimeException(Status.INVALID_ARGUMENT) { + throw e.asStatusRuntimeException( + Status.Code.INVALID_ARGUMENT, "Measurement Calculation Time Interval not found in Report" - } + ) } } @@ -61,7 +62,7 @@ class PostgresReportsService( .report } } catch (e: ReportNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Report not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Report not found") } } @@ -79,7 +80,7 @@ class PostgresReportsService( .report } } catch (e: ReportNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Report not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Report not found") } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersService.kt index f0fff0a1079..c08fbcf3ca7 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMeasurementConsumersService.kt @@ -34,7 +34,10 @@ class PostgresMeasurementConsumersService( try { return CreateMeasurementConsumer(request).execute(client, idGenerator) } catch (e: MeasurementConsumerAlreadyExistsException) { - e.throwStatusRuntimeException(Status.ALREADY_EXISTS) { "Measurement Consumer already exists" } + throw e.asStatusRuntimeException( + Status.Code.ALREADY_EXISTS, + "Measurement Consumer already exists" + ) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMetricsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMetricsService.kt index 6fd48040f32..6541e0d4fef 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMetricsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresMetricsService.kt @@ -68,11 +68,12 @@ class PostgresMetricsService( return try { CreateMetrics(listOf(request)).execute(client, idGenerator).first() } catch (e: ReportingSetNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Reporting Set not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Reporting Set not found.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Measurement Consumer not found." - } + ) } } @@ -106,11 +107,12 @@ class PostgresMetricsService( metrics += CreateMetrics(request.requestsList).execute(client, idGenerator) } } catch (e: ReportingSetNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Reporting Set not found." } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Reporting Set not found.") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, "Measurement Consumer not found." - } + ) } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsService.kt index a6fadcaaf4b..24016bf1bef 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/PostgresReportingSetsService.kt @@ -62,9 +62,12 @@ class PostgresReportingSetsService( return try { CreateReportingSet(request).execute(client, idGenerator) } catch (e: ReportingSetNotFoundException) { - e.throwStatusRuntimeException(Status.NOT_FOUND) { "Reporting Set not found" } + throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Reporting Set not found") } catch (e: MeasurementConsumerNotFoundException) { - e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement Consumer not found" } + throw e.asStatusRuntimeException( + Status.Code.FAILED_PRECONDITION, + "Measurement Consumer not found" + ) } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/BUILD.bazel index 310d6e54f6b..5841d3ca8a4 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/BUILD.bazel +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/BUILD.bazel @@ -8,6 +8,8 @@ kt_jvm_library( name = "internal_exception", srcs = ["ReportingInternalException.kt"], deps = [ + "//src/main/proto/google/rpc:error_details_kt_jvm_proto", + "//src/main/proto/google/rpc:status_kt_jvm_proto", "//src/main/proto/wfa/measurement/internal/reporting:error_code_kt_jvm_proto", "@wfa_common_jvm//imports/java/com/google/protobuf", "@wfa_common_jvm//imports/java/io/grpc/protobuf", diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/ReportingInternalException.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/ReportingInternalException.kt index 1fc607e0bec..d0d316a6d95 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/ReportingInternalException.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/ReportingInternalException.kt @@ -14,12 +14,12 @@ package org.wfanet.measurement.reporting.service.internal -import com.google.rpc.ErrorInfo +import com.google.protobuf.Any import com.google.rpc.errorInfo -import io.grpc.Metadata +import com.google.rpc.status import io.grpc.Status import io.grpc.StatusRuntimeException -import io.grpc.protobuf.ProtoUtils +import io.grpc.protobuf.StatusProto import org.wfanet.measurement.internal.reporting.ErrorCode /** TODO(tristanvuong2021): Add context when each of these exceptions are thrown. */ @@ -35,30 +35,24 @@ sealed class ReportingInternalException : Exception { this.code = code } - fun throwStatusRuntimeException( - status: Status = Status.INVALID_ARGUMENT, - provideDescription: () -> String, - ): Nothing { - val info = errorInfo { - reason = code.toString() - domain = ErrorInfo::class.qualifiedName.toString() - metadata.putAll(context) + fun asStatusRuntimeException( + statusCode: Status.Code, + message: String = this.message!! + ): StatusRuntimeException { + val statusProto = status { + code = statusCode.value() + this.message = message + details += + Any.pack( + errorInfo { + reason = this@ReportingInternalException.code.toString() + domain = ErrorCode.getDescriptor().fullName + metadata.putAll(context) + } + ) } - - val metadata = Metadata() - metadata.put(ProtoUtils.keyForProto(info), info) - - throw status - .withDescription(provideDescription() + contextToString()) - .asRuntimeException(metadata) + return StatusProto.toStatusRuntimeException(statusProto) } - - private fun contextToString() = context.entries.joinToString(prefix = " ", separator = " ") -} - -fun StatusRuntimeException.getErrorInfo(): ErrorInfo? { - val key = ProtoUtils.keyForProto(ErrorInfo.getDefaultInstance()) - return trailers?.get(key) } class ReportingSetAlreadyExistsException( diff --git a/src/main/proto/google/rpc/BUILD.bazel b/src/main/proto/google/rpc/BUILD.bazel new file mode 100644 index 00000000000..cb644b840f1 --- /dev/null +++ b/src/main/proto/google/rpc/BUILD.bazel @@ -0,0 +1,17 @@ +# TODO(@SanjayVas): Move this file to common-jvm. + +load("@wfa_common_jvm//build/kt_jvm_proto:defs.bzl", "kt_jvm_proto_library") + +package(default_visibility = ["//visibility:public"]) + +kt_jvm_proto_library( + name = "error_details_kt_jvm_proto", + srcs = ["@com_google_googleapis//google/rpc:error_details_proto"], + deps = ["@com_google_googleapis//google/rpc:rpc_java_proto"], +) + +kt_jvm_proto_library( + name = "status_kt_jvm_proto", + srcs = ["@com_google_googleapis//google/rpc:status_proto"], + deps = ["@com_google_googleapis//google/rpc:rpc_java_proto"], +) diff --git a/src/main/proto/wfa/measurement/internal/kingdom/BUILD.bazel b/src/main/proto/wfa/measurement/internal/kingdom/BUILD.bazel index 5a9ce317c37..92a3514711d 100644 --- a/src/main/proto/wfa/measurement/internal/kingdom/BUILD.bazel +++ b/src/main/proto/wfa/measurement/internal/kingdom/BUILD.bazel @@ -459,9 +459,6 @@ proto_and_java_proto_library(name = "exchange_workflow") proto_library( name = "error_code_proto", srcs = ["error_code.proto"], - deps = [ - "@com_google_googleapis//google/rpc:error_details_proto", - ], ) java_proto_library( diff --git a/src/main/proto/wfa/measurement/internal/reporting/BUILD.bazel b/src/main/proto/wfa/measurement/internal/reporting/BUILD.bazel index 3d3f693d36e..a7800f77b83 100644 --- a/src/main/proto/wfa/measurement/internal/reporting/BUILD.bazel +++ b/src/main/proto/wfa/measurement/internal/reporting/BUILD.bazel @@ -6,9 +6,6 @@ package(default_visibility = ["//:__subpackages__"]) proto_and_java_proto_library( name = "error_code", - deps = [ - "@com_google_googleapis//google/rpc:error_details_proto", - ], ) proto_and_java_proto_library(