-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Errors handling between Rust and JS #80
feat: Errors handling between Rust and JS #80
Conversation
@@ -25,13 +25,14 @@ export class BankingApp { | |||
|
|||
async init() { | |||
this.initiator = await Initiator.init(sdkConfig) |
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.
If kafka is down the error will bubble into main method. There is an example how we can handle typed errors.
@@ -71,6 +111,16 @@ new Promise(async (resolve) => { | |||
queue, | |||
fnFinish, | |||
) | |||
await app.init() | |||
try { |
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.
this is example where caller can deal with specific errors. I skipped else statement here.
} | ||
} | ||
|
||
export { |
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.
Export only what we allow client to use.
import { isSdkError } from "./internal" | ||
import { TalosSdkError } from "." | ||
|
||
export class Initiator { |
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.
Wrapper with error handler.
@@ -0,0 +1,5 @@ | |||
import { SDK_CONTAINER_TYPE } from "cohort_sdk_js" |
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 value is managed in the Rust layer.
|
||
// println!("Initiator.certify(): after cohort.certify(...)"); | ||
Ok("Success".to_string()) | ||
let _res = self.cohort.certify(&make_new_request, &ooo_impl).await.map_err(map_error)?; |
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.
That's where we use our error handling and packaging logic.
…encies on images.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## feature/cohort_replicator_js #80 +/- ##
===============================================================
Coverage ? 58.16%
===============================================================
Files ? 103
Lines ? 5314
Branches ? 0
===============================================================
Hits ? 3091
Misses ? 2223
Partials ? 0 ☔ View full report in Codecov by Sentry. |
* feat: Add wrapper and error handler for Replicator JS. * feat: Add ReplicatorError and map it to JS layer. * fix: Move dev dependencies into relevant section in the package.json
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.
Nice 👍
* fix: Refactor strucutre to define re-usabe elements. * fix: Move replicator callback traits into callbacks.rs * feat: Add Replicator JS wrapper * feat: Cohort Replicator JS * feat: Use launch parameters to configure runtime settings. * feat: Use i64 when converting numbers from JS to Rust. * chore: Remove unused file. * fix: Use better error handling inside replicator install() * chore: Add logging to Replicator JS * fix: Convert snapshot version to number in JS * feat: Add missing DB migrartions; Organise Makefile commands. (#79) * feat: Errors handling between Rust and JS (#80) * feat: Initial draft for errors handling between Rust and JS * fix: Remove cohort_sdk_js dependency, instead declare optional dependencies on images. * fix: Inject using serde annotation _typ during serialisation into JSON. * fix: Improve error handling when processig callback calls between JS and RS. * feat: Add ReplicatorError and map it to JS layer. (#81) * feat: Add wrapper and error handler for Replicator JS. * feat: Add ReplicatorError and map it to JS layer. * fix: Move dev dependencies into relevant section in the package.json
The main ideas:
Throwing error
ClientError
so, there was no need to do any changes here.SdkErrorKind
in RS and map its values toClientError.kind
, in our case that isClientErrorKind.rs
enum.SdkErrorContainer" whose purpose is to collect attributes from
ClientError` and make them a) serialisable to JSON b) transferrable to JS layercohort_sdk_js
is handling rust error it packs data intoSdkErrorContainer
, serialises it to json + string and sets intonapi::Error.message
Receiving and mapping error
cohort_sdk_client
JS project which wraps every public service class fromcohort_sdk_js
. For example,cohort_sdk_js
exposes logical service "initiator". We program this service ascohort_sdk_js::InternalInitiator
and do not let JS client to use it directly. Instead, we wrap this class into "cohort_sdk_client::Initiator" so that every public method is a delegate withtry .. catch.
When catching error we catch a normal JS error, use it'smessage
attribute to parse intoSdkErrorContainer
. Then we re-throw resulting info as "official"TalosSdkError
. This is JS class extending JS Error with enum inside it.The end client only aware of:
cohort_sdk_client
as dependencycohort_sdk_client::Initiator
as service class,cohort_sdk_client::TalosSdkError
as error which will be thown from service classes. It hasTalosSdkError.kind
asSdkErrorKind
enum.