Refactor CRUD operations to use Arrow's Raise for error handling#88
Refactor CRUD operations to use Arrow's Raise for error handling#88nomisRev wants to merge 1 commit intosmyrgeorge:mainfrom
Raise for error handling#88Conversation
…stead of returning `DbResult`.
|
Hey @nomisRev Recently, I started developing a new library (or toolkit if you like, I'm trying to avoid the term framework here), the name is You can find the ktkit here: Take a look at this example: The error mapper Now, with the current implementation I can easily map the error domain from sqlx4k (DbResult) to the app domain (AppResult) with just an extension method. Also, in the example that I sent you, notice that the class ExecContext(
val reqId: String,
val reqTs: Instant = Clock.System.now(),
val principal: Principal,
...
) : Raise<ErrorSpec>, TracingContext by tracing, CoroutineContext.Element {Notice the If we make the change that you are proposing how the code should be changed? Edit:In the example that I sent you I should probably change the function context(_: ExecContext, _: Transaction)
suspend fun test(): List<Test> {
log.info { "Fetching all tests" }
sqlx4k() // Compilation error
return findAll().bind().also {
log.info { "Fetched ${it.size} tests" }
}
}
context(_: Raise<SQLError>)
fun sqlx4k(): Long = 5In this case how can call the val a = either { test1() }.toAppResult().bind()So the above example will be something like: context(_: ExecContext, _: Transaction)
suspend fun test(): List<Test> {
log.info { "Fetching all tests" }
val a = either { test1() }.toAppResult().bind()
return findAll().bind().also {
log.info { "Fetched ${it.size} tests" }
}
}Is there any other way? |
|
Hello @nomisRev You're right, the way that you are proposing works way better, and I prefer way more the ergonomics this way. So, if you're willing, go on and make the changes in the Thanks a lot |
Hey!
I saw Sqlx4k come by again on my timeline, and wanted to check up on the recent updates when I saw Arrow 😁 When I checked the code I saw there context parameters support, so I made a small PR to show what it would like lifting the error to the context.
This would require updating the codegen. I could give it a shot if you like this proposal.