-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPP-686][Self-service error codes] Removing default error factories #11403
Changes from 7 commits
21a57ef
693e106
e514ec9
f476ed5
5bacf4b
5c383ce
18ca5c3
a48e489
2692452
3a0a74b
cbd42a9
acddaad
3769bae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ da_scala_library( | |
deps = [ | ||
"//daml-lf/data", | ||
"//language-support/scala/bindings", | ||
"//ledger/ledger-api-common", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be anymore. Weird. I thought Bazel would error out any time a dependency is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing |
||
"//ledger/ledger-api-health", | ||
"//ledger/ledger-configuration", | ||
"//ledger/ledger-offset", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,6 +402,20 @@ class ErrorFactories private (errorCodesVersionSwitcher: ErrorCodesVersionSwitch | |
v2 = LedgerApiErrors.ServiceNotRunning.Reject().asGrpcError, | ||
) | ||
|
||
def trackerFailure(msg: String)(implicit | ||
contextualizedErrorLogger: ContextualizedErrorLogger | ||
): StatusRuntimeException = | ||
errorCodesVersionSwitcher.choose( | ||
v1 = { | ||
val builder = Status | ||
.newBuilder() | ||
.setCode(Code.INTERNAL.value()) | ||
.setMessage(msg) | ||
grpcError(builder.build()) | ||
}, | ||
v2 = LedgerApiErrors.InternalError.CommandTrackerInternalError(msg).asGrpcError, | ||
) | ||
|
||
/** Transforms Protobuf [[Status]] objects, possibly including metadata packed as [[ErrorInfo]] objects, | ||
* into exceptions with metadata in the trailers. | ||
* | ||
|
@@ -427,11 +441,7 @@ class ErrorFactories private (errorCodesVersionSwitcher: ErrorCodesVersionSwitch | |
} | ||
} | ||
|
||
/** Object exposing the legacy error factories. | ||
* TODO error codes: Remove default implementation once all Ledger API services | ||
* output versioned error codes. | ||
Comment on lines
-443
to
-444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally, one removed! 🍾 |
||
*/ | ||
object ErrorFactories extends ErrorFactories(new ErrorCodesVersionSwitcher(false)) { | ||
object ErrorFactories { | ||
def apply(errorCodesVersionSwitcher: ErrorCodesVersionSwitcher): ErrorFactories = | ||
new ErrorFactories(errorCodesVersionSwitcher) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import scala.concurrent.{ExecutionContext, Future, TimeoutException} | |
class SynchronousResponse[Input, Entry, AcceptedEntry]( | ||
strategy: SynchronousResponse.Strategy[Input, Entry, AcceptedEntry], | ||
timeToLive: Duration, | ||
errorFactories: ErrorFactories, | ||
) { | ||
|
||
def submitAndWait(submissionId: Ref.SubmissionId, input: Input)(implicit | ||
|
@@ -52,7 +53,7 @@ class SynchronousResponse[Input, Entry, AcceptedEntry]( | |
.runWith(Sink.head) | ||
.recoverWith { case _: TimeoutException => | ||
Future.failed( | ||
ErrorFactories.aborted("Request timed out", definiteAnswer = Some(false)) | ||
errorFactories.aborted("Request timed out", definiteAnswer = Some(false)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi @tudor-da There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
) | ||
} | ||
.flatten | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import akka.stream.{Materializer, OverflowStrategy, QueueOfferResult} | |
import akka.{Done, NotUsed} | ||
import com.codahale.metrics.{Counter, Timer} | ||
import com.daml.dec.DirectExecutionContext | ||
import com.daml.error.DamlContextualizedErrorLogger | ||
import com.daml.ledger.client.services.commands.CommandSubmission | ||
import com.daml.ledger.client.services.commands.CommandTrackerFlow.Materialized | ||
import com.daml.ledger.client.services.commands.tracker.CompletionResponse._ | ||
|
@@ -16,15 +17,14 @@ import com.daml.metrics.InstrumentedSource | |
import com.daml.platform.apiserver.services.tracking.QueueBackedTracker._ | ||
import com.daml.platform.server.api.validation.ErrorFactories | ||
import com.daml.util.Ctx | ||
import com.google.rpc.Status | ||
import io.grpc.Status.Code | ||
import io.grpc.{Status => GrpcStatus} | ||
|
||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Await, ExecutionContext, Future, Promise} | ||
import scala.util.{Failure, Success} | ||
import scala.util.{Failure, Success, Try} | ||
|
||
/** Tracks SubmitAndWaitRequests. | ||
* | ||
* @param queue The input queue to the tracking flow. | ||
*/ | ||
private[services] final class QueueBackedTracker( | ||
|
@@ -110,6 +110,7 @@ private[services] object QueueBackedTracker { | |
capacityCounter: Counter, | ||
lengthCounter: Counter, | ||
delayTimer: Timer, | ||
errorFactories: ErrorFactories, | ||
)(implicit materializer: Materializer, loggingContext: LoggingContext): QueueBackedTracker = { | ||
val ((queue, mat), done) = InstrumentedSource | ||
.queue[QueueInput]( | ||
|
@@ -147,19 +148,17 @@ private[services] object QueueBackedTracker { | |
mat.trackingMat.onComplete( | ||
// no error expected here -- if there is one, we're at a total loss. | ||
// FIXME(mthvedt): we should shut down everything in this case. | ||
_.get.values | ||
.foreach( | ||
_.failure( | ||
ErrorFactories.grpcError( | ||
Status | ||
.newBuilder() | ||
.setCode(Code.INTERNAL.value()) | ||
.setMessage(promiseCancellationDescription) | ||
.build() | ||
) | ||
(aTry: Try[Map[_, Promise[_]]]) => { | ||
val promises: Iterable[Promise[_]] = aTry.get.values | ||
val errorLogger = new DamlContextualizedErrorLogger(logger, loggingContext, None) | ||
promises.foreach(p => | ||
p.failure( | ||
errorFactories.trackerFailure(msg = promiseCancellationDescription)(errorLogger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi @tudor-da There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to keep those comments in the right place if changing this piece. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized I'm not sure what that comment precisely refers to. Moving the comments right before it. |
||
) | ||
) | ||
} | ||
)(DirectExecutionContext) | ||
|
||
}(DirectExecutionContext) | ||
|
||
new QueueBackedTracker(queue, done) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ import scala.concurrent.Future | |
private[platform] final class LedgerBackedIndexService( | ||
ledger: ReadOnlyLedger, | ||
participantId: Ref.ParticipantId, | ||
errorFactories: ErrorFactories, | ||
) extends IndexService { | ||
private val logger = ContextualizedLogger.get(getClass) | ||
|
||
|
@@ -144,7 +145,7 @@ private[platform] final class LedgerBackedIndexService( | |
case Some(end) if begin > end => | ||
Source.failed( | ||
// TODO error codes: Replace with LedgerApiErrors.ReadErrors.RequestedOffsetAfterLedgerEnd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's address this TODO:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you proposed means changing V1 (from INVALID_ARGUMENT to OUT_OF_RANGE). Is it fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scratch first comment. Actually using |
||
ErrorFactories.invalidArgument(None)( | ||
errorFactories.invalidArgument(None)( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi @tudor-da |
||
s"End offset ${end.toApiString} is before Begin offset ${begin.toApiString}." | ||
)(new DamlContextualizedErrorLogger(logger, loggingContext, None)) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this comment? This error appears under
LedgerApiErrors.InternalError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is the what is now called
InternalError
is really "internal errors related to the interpreter":There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, the explanation was wrong here. Fine, let's leave as it