From 3d7ba64e5739b8fab03c5ab45aded2a137b94072 Mon Sep 17 00:00:00 2001 From: Pawel Batko Date: Tue, 2 Nov 2021 15:40:12 +0100 Subject: [PATCH] [DPP-701] Maybe missed error code conversions --- .../scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala | 3 +++ .../lf/engine/script/ledgerinteraction/JsonLedgerClient.scala | 1 + .../ledger/rxjava/grpc/helpers/TransactionsServiceImpl.scala | 1 + .../com/daml/error/definitions/RejectionGenerators.scala | 1 + .../client/services/commands/tracker/CompletionResponse.scala | 2 ++ .../platform/server/api/validation/ErrorFactoriesSpec.scala | 4 ++++ .../apiserver/services/tracking/QueueBackedTracker.scala | 1 + .../src/main/scala/platform/store/Conversions.scala | 1 + .../ledger/participant/state/kvutils/api/BatchingQueue.scala | 2 ++ .../scala/com/daml/ledger/validator/ValidatingCommitter.scala | 2 ++ .../ledger/validator/batch/BatchedValidatingCommitter.scala | 1 + .../daml/ledger/participant/state/v2/SubmissionResult.scala | 1 + .../main/scala/platform/sandbox/stores/ledger/Rejection.scala | 1 + .../sandbox/stores/ledger/inmemory/InMemoryLedger.scala | 1 + .../scala/platform/sandbox/services/SandboxResetService.scala | 2 ++ .../com/daml/ledger/sandbox/ReadWriteServiceBridge.scala | 2 ++ 16 files changed, 26 insertions(+) diff --git a/compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala b/compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala index 060296d1b2fe..94f0eaf67f83 100644 --- a/compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala +++ b/compiler/scenario-service/server/src/main/scala/com/digitalasset/daml/lf/ScenarioServiceMain.scala @@ -72,6 +72,7 @@ object ScenarioServiceMain extends App { object ScenarioService { private def notFoundContextError(id: Long): StatusRuntimeException = + // TODO error codes: Adapt V2 ? Status.NOT_FOUND.withDescription(s" context $id not found!").asRuntimeException } @@ -292,8 +293,10 @@ class ScenarioService(implicit } catch { case e: archive.Error => + // TODO error codes: Adapt V2 ? respObs.onError(Status.INVALID_ARGUMENT.withDescription(e.msg).asRuntimeException()) case NonFatal(e) => + // TODO error codes: Adapt V2 ? respObs.onError(Status.INTERNAL.withDescription(e.toString).asRuntimeException()) } } diff --git a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/JsonLedgerClient.scala b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/JsonLedgerClient.scala index 74b9e682f0e1..5142b4a370af 100644 --- a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/JsonLedgerClient.scala +++ b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/ledgerinteraction/JsonLedgerClient.scala @@ -439,6 +439,7 @@ class JsonLedgerClient( // TODO (MK) Using a grpc exception here doesn’t make that much sense. // We should refactor this to provide something more general. Future.successful( + // TODO error codes: Adapt V2 ? Left(new StatusRuntimeException(Status.UNKNOWN.withDescription(errors.toString))) ) case ErrorResponse(errors, status) => diff --git a/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/helpers/TransactionsServiceImpl.scala b/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/helpers/TransactionsServiceImpl.scala index a8b8ca95cafb..f6553d0c8b64 100644 --- a/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/helpers/TransactionsServiceImpl.scala +++ b/language-support/java/bindings-rxjava/src/test/scala/com/daml/ledger/rxjava/grpc/helpers/TransactionsServiceImpl.scala @@ -55,6 +55,7 @@ final class TransactionsServiceImpl(ledgerContent: Observable[LedgerItem]) Metadata.Key.of("cause", Metadata.ASCII_STRING_MARSHALLER), s"BEGIN should be strictly smaller than END. Found BEGIN '${request.getBegin}' and END '${request.getEnd}'", ) + // TODO error codes: Adapt V2 ? responseObserver.onError(Status.INVALID_ARGUMENT.asRuntimeException(metadata)) } else { ledgerContent.subscribe(new Observer[LedgerItem] { diff --git a/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala b/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala index ed1be44466f4..cee3cad0be6c 100644 --- a/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala +++ b/ledger/error/src/main/scala/com/daml/error/definitions/RejectionGenerators.scala @@ -191,6 +191,7 @@ class RejectionGenerators(conformanceMode: Boolean) { // TODO error codes: This converter is deprecated and should be removed // Instead of using this, construct proper validation errors in callers of this method // and only convert to StatusRuntimeExceptions when dispatched (e.g. in ApiSubmissionService) + @deprecated("not used in daml sdk") def validationFailure(reject: StatusRuntimeException)(implicit contextualizedErrorLogger: ContextualizedErrorLogger ): StatusRuntimeException = { diff --git a/ledger/ledger-api-client/src/main/scala/com/digitalasset/ledger/client/services/commands/tracker/CompletionResponse.scala b/ledger/ledger-api-client/src/main/scala/com/digitalasset/ledger/client/services/commands/tracker/CompletionResponse.scala index 04fcee4ee313..1d39cf55216e 100644 --- a/ledger/ledger-api-client/src/main/scala/com/digitalasset/ledger/client/services/commands/tracker/CompletionResponse.scala +++ b/ledger/ledger-api-client/src/main/scala/com/digitalasset/ledger/client/services/commands/tracker/CompletionResponse.scala @@ -85,6 +85,7 @@ object CompletionResponse { } private[daml] def toException(response: TrackedCompletionFailure): StatusException = + // TODO error codes: Adapt V2 ? response match { case QueueCompletionFailure(failure) => val metadata = extractMetadata(failure) @@ -115,6 +116,7 @@ object CompletionResponse { private def buildException(metadata: Map[String, String], status: StatusJavaProto.Builder) = { val details = mergeDetails(metadata, status) + // TODO error codes: Adapt V2 ? protobuf.StatusProto.toStatusException( status .clearDetails() diff --git a/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/platform/server/api/validation/ErrorFactoriesSpec.scala b/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/platform/server/api/validation/ErrorFactoriesSpec.scala index 484f731a6c5e..0d6e78973f62 100644 --- a/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/platform/server/api/validation/ErrorFactoriesSpec.scala +++ b/ledger/ledger-api-common/src/test/suite/scala/com/digitalasset/platform/server/api/validation/ErrorFactoriesSpec.scala @@ -37,6 +37,10 @@ class ErrorFactoriesSpec extends AnyWordSpec with Matchers with TableDrivenPrope ErrorDetails.RequestInfoDetail("trace-id") "ErrorFactories" should { + "do it" in { + Code.values().foreach(println) + fail() + } "return sqlTransientException" in { val failureReason = "some db transient failure" val someSqlTransientException = new SQLTransientException(failureReason) diff --git a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/tracking/QueueBackedTracker.scala b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/tracking/QueueBackedTracker.scala index 97b8d9501a53..79b06142cb09 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/tracking/QueueBackedTracker.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/apiserver/services/tracking/QueueBackedTracker.scala @@ -49,6 +49,7 @@ private[services] final class QueueBackedTracker( _.left.map(completionFailure => QueueCompletionFailure(completionFailure)) ) case QueueOfferResult.Failure(t) => + // TODO error codes: Adapt V2 ? failedQueueSubmission( GrpcStatus.ABORTED .withDescription(s"Failed to enqueue: ${t.getClass.getSimpleName}: ${t.getMessage}") diff --git a/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala b/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala index adc9aa23f3f8..987a3e9ff7b4 100644 --- a/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala +++ b/ledger/participant-integration-api/src/main/scala/platform/store/Conversions.scala @@ -332,6 +332,7 @@ private[platform] object Conversions { import RejectionReasonOps._ def toParticipantStateRejectionReason: state.Update.CommandRejected.RejectionReasonTemplate = + // TODO error codes: Adapt V2 ? rejectionReason match { case domain.RejectionReason.Inconsistent(reason) => newRejectionReason(Status.Code.ABORTED, s"Inconsistent: $reason") diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/BatchingQueue.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/BatchingQueue.scala index 2a26a9f19ecc..c6e2d93361c7 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/BatchingQueue.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/participant/state/kvutils/api/BatchingQueue.scala @@ -121,6 +121,7 @@ case class DefaultBatchingQueue( ) ) case f: QueueOfferResult.Failure => + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value, @@ -128,6 +129,7 @@ case class DefaultBatchingQueue( ) ) case QueueOfferResult.QueueClosed => + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value, diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/ValidatingCommitter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/ValidatingCommitter.scala index b65de5532a67..c98f0691ced5 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/ValidatingCommitter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/ValidatingCommitter.scala @@ -65,6 +65,7 @@ class ValidatingCommitter[LogResult]( postCommit(value) SubmissionResult.Acknowledged case Left(MissingInputState(keys)) => + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value, @@ -72,6 +73,7 @@ class ValidatingCommitter[LogResult]( ) ) case Left(ValidationError(reason)) => + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value, diff --git a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/batch/BatchedValidatingCommitter.scala b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/batch/BatchedValidatingCommitter.scala index 8dfd13035e90..867571814363 100644 --- a/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/batch/BatchedValidatingCommitter.scala +++ b/ledger/participant-state/kvutils/src/main/scala/com/daml/ledger/validator/batch/BatchedValidatingCommitter.scala @@ -78,6 +78,7 @@ class BatchedValidatingCommitter[LogResult]( Future.successful(SubmissionResult.Acknowledged) case Failure(exception) => Future.successful( + // TODO error codes: Adapt V2 ? SubmissionResult .SynchronousError(Status(Code.INTERNAL.value, exception.getLocalizedMessage)) ) diff --git a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/SubmissionResult.scala b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/SubmissionResult.scala index dc6d39d277be..5d3538211756 100644 --- a/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/SubmissionResult.scala +++ b/ledger/participant-state/src/main/scala/com/daml/ledger/participant/state/v2/SubmissionResult.scala @@ -28,6 +28,7 @@ object SubmissionResult { override val description: String = s"Submission failed with error ${status.message}" def exception: StatusRuntimeException = + // TODO error codes: Adapt V2 ? protobuf.StatusProto.toStatusRuntimeException(GrpcStatus.toJavaProto(status)) } diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Rejection.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Rejection.scala index c1a9864898a7..2e636c90219f 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Rejection.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/Rejection.scala @@ -28,6 +28,7 @@ object Rejection { domain.RejectionReason.InvalidLedgerTime(description) override lazy val toStateRejectionReason: state.Update.CommandRejected.RejectionReasonTemplate = + // TODO error codes: Adapt V2 ? state.Update.CommandRejected.FinalReason( RpcStatus.of( code = Status.Code.ABORTED.value(), diff --git a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala index fec72b19a707..1da51663193c 100644 --- a/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala +++ b/ledger/sandbox-classic/src/main/scala/platform/sandbox/stores/ledger/inmemory/InMemoryLedger.scala @@ -744,6 +744,7 @@ private[sandbox] final class InMemoryLedger( loggingContext: LoggingContext ): Future[Unit] = // sandbox-classic in-memory ledger does not support pruning + // TODO error codes: Adapt V2 ? Future.failed(Status.UNIMPLEMENTED.asRuntimeException()) } diff --git a/ledger/sandbox-common/src/main/scala/platform/sandbox/services/SandboxResetService.scala b/ledger/sandbox-common/src/main/scala/platform/sandbox/services/SandboxResetService.scala index 3133b1a98bb8..b04ed26f5a60 100644 --- a/ledger/sandbox-common/src/main/scala/platform/sandbox/services/SandboxResetService.scala +++ b/ledger/sandbox-common/src/main/scala/platform/sandbox/services/SandboxResetService.scala @@ -44,6 +44,7 @@ class SandboxResetService( serverCallHandler: ServerCallHandler[ReqT, RespT], ): Listener[ReqT] = { if (resetInitialized.get) { + // TODO error codes: Adapt V2 ? throw new StatusRuntimeException( Status.UNAVAILABLE.withDescription("Sandbox server is currently being reset") ) @@ -71,6 +72,7 @@ class SandboxResetService( logger.info("Initiating server reset.") if (!resetInitialized.compareAndSet(false, true)) + // TODO error codes: Adapt V2 ? throw new StatusRuntimeException( Status.FAILED_PRECONDITION.withDescription("Sandbox server is currently being reset") ) diff --git a/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala b/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala index d4bf4db3b0ab..2cb815074abe 100644 --- a/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala +++ b/ledger/sandbox-on-x/src/main/scala/com/daml/ledger/sandbox/ReadWriteServiceBridge.scala @@ -261,6 +261,7 @@ object ReadWriteServiceBridge { ) case QueueOfferResult.Failure(throwable) => logger.error("Error enqueueing new submission.", throwable) + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value, @@ -269,6 +270,7 @@ object ReadWriteServiceBridge { ) case QueueOfferResult.QueueClosed => logger.error("Error enqueueing new submission: queue is closed.") + // TODO error codes: Adapt V2 ? SubmissionResult.SynchronousError( Status( Code.INTERNAL.value,