Skip to content
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

Improve error handling #2

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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