question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide typed exceptions (java bindings)

See original GitHub issue

What is the problem you want to solve?

A lot of extra code is written to wrap the StatusRuntimeException with named/typed exceptions for the ledger api call response.

What is the solution you would propose?

Provide typed exceptions that provide easy understanding of the business error occurring

Example:

  1. Create a User but the user already exists: throw a UserExistsException with cause: StatusRuntimeException.
  2. Get User but user does not exist: throw a UserNotFoundException with cause: StatusRuntimeException.
  3. Get Contract but does not exist: throw ContractNotFoundException with cause: StatusRuntimeException.

etc etc

Yes we can inspect the status codes and contents of the messages being returned by the ledger api, but it is boiler plate code that needs to be re-written each time. If you provided typed business exceptions, the boiler plate error handling code would be significantly reduced.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
daravepcommented, Jul 15, 2022

One additional note: we might want to add something like

class ChaosInterceptor
    extends ServerInterceptor {

  override def interceptCall[ReqT, RespT](
      call: ServerCall[ReqT, RespT],
      headers: Metadata,
      next: ServerCallHandler[ReqT, RespT],
  ): ServerCall.Listener[ReqT] = {
     // inject random outages
  }

we should add that and turn it on by default on the sandbox. if you build applications against it, it will inject random failures to force you to think about error handling (and let you test your error handling).

0reactions
daravepcommented, Jul 15, 2022

@StephenOTT Please have a read about our error codes: https://docs.daml.com/app-dev/grpc/error-codes.html#work-with-error-codes

I would strongly advise to not invent another way to handle errors, but rather make the error-code information accessible.

  1. Every error comes with an error category: https://docs.daml.com/app-dev/grpc/error-codes.html#transientserverfailure
  2. Every error category has an explicit advise on how to deal with that error. Example: https://docs.daml.com/app-dev/grpc/error-codes.html#invalidgivencurrentsystemstateresourceexists
  3. Ideally, we surface that retry information.
  4. We also need to include the rich error information. E.g. if you get contention on keys, the rich GRPC error contains the information on which key created the contention.
  5. Here is our crappy scala code to decode the error-codes into a usable form: https://github.com/DACH-NY/canton/blob/main/community/common/src/main/scala/com/digitalasset/canton/error/DecodedRpcStatus.scala#L22
Read more comments on GitHub >

github_iconTop Results From Across the Web

Types of Exceptions in Java - Stackify
Learn about the different types of exceptions in Java (checked and unchecked) and see specific examples.
Read more >
Types of Exception in Java with Examples - GeeksforGeeks
Java defines several types of exceptions that relate to its various class libraries. Java also allows users to define their own exceptions.
Read more >
Java Exceptions Hierarchy Explained - Rollbar
Exceptions that can occur at compile-time are called checked exceptions since they need to be explicitly checked and handled in code. Classes ...
Read more >
Common Java Exceptions - Baeldung
This tutorial focuses on some common Java exceptions. ... This class is then subclassed into checked exceptions and unchecked exceptions.
Read more >
11.2. Compile-Time Checking of Exceptions
The Java programming language requires that a program contains handlers for checked exceptions which can result from execution of a method or constructor....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found