Skip to content

Commit

Permalink
Improving error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Sep 13, 2024
1 parent 715174e commit 036ade8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/main/scala/com/rawlabs/das/server/DASSdkManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class DASSdkManager(implicit settings: RawSettings) extends StrictLogging {
def getDAS(dasId: DASId): DASSdk = {
dasSdksInMemoryLock.synchronized {
logger.debug(s"Fetching DAS with ID: $dasId")
dasSdksInMemory.getOrElseUpdate(dasId, getDASFromRemote(dasId))
dasSdksInMemory.getOrElseUpdate(
dasId,
getDASFromRemote(dasId).getOrElse(throw new IllegalArgumentException(s"DAS not found: $dasId"))
)
}
}

Expand Down Expand Up @@ -166,10 +169,8 @@ class DASSdkManager(implicit settings: RawSettings) extends StrictLogging {
* @param dasId The DAS ID to retrieve.
* @return The DAS instance.
*/
private def getDASFromRemote(dasId: DASId): DASSdk = {
logger.error(s"getDASFromRemote not implemented for DAS ID: $dasId")
// TODO: Implement this method - go to creds to get the definition
throw new NotImplementedError("getDASFromRemote not implemented")
private def getDASFromRemote(dasId: DASId): Option[DASSdk] = {
None
}

}
2 changes: 1 addition & 1 deletion src/main/scala/com/rawlabs/das/server/DASServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DASServer(implicit settings: RawSettings) {
.forPort(port)
.addService(registrationService)
.addService(tablesService)
.intercept(new ExceptionHandlingInterceptor)
.intercept(new ThrowableHandlingInterceptor)
.build()
.start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package com.rawlabs.das.server
import com.typesafe.scalalogging.StrictLogging
import io.grpc._

class ExceptionHandlingInterceptor extends ServerInterceptor with StrictLogging {
class ThrowableHandlingInterceptor extends ServerInterceptor with StrictLogging {

override def interceptCall[ReqT, RespT](
call: ServerCall[ReqT, RespT],
Expand All @@ -25,7 +25,7 @@ class ExceptionHandlingInterceptor extends ServerInterceptor with StrictLogging

val serverCall = new ForwardingServerCall.SimpleForwardingServerCall[ReqT, RespT](call) {
override def close(status: Status, trailers: Metadata): Unit = {
// Convert any exception to a gRPC status
// Convert any throwable to a gRPC status
if (status.getCause != null) {
val newStatus = status.withDescription(status.getCause.getMessage).withCause(status.getCause)
super.close(newStatus, trailers)
Expand All @@ -42,10 +42,10 @@ class ExceptionHandlingInterceptor extends ServerInterceptor with StrictLogging
try {
super.onHalfClose()
} catch {
case ex: Exception =>
logger.debug(s"Exception caught in interceptor", ex)
case t: Throwable =>
logger.debug(s"Throwable caught in interceptor", t)
// Close the call with an error status
serverCall.close(Status.INTERNAL.withDescription(ex.getMessage).withCause(ex), new Metadata())
serverCall.close(Status.INTERNAL.withDescription(t.getMessage).withCause(t), new Metadata())
}
}
}
Expand Down

0 comments on commit 036ade8

Please sign in to comment.