Fork me on GitHub
#reitit
<
2020-09-28
>
ikitommi07:09:30

@eyaldocs do you mean core/frontend or the backend coercion? will answer for both: • frontend: easy to add non-throwing variant • backend: few things to do: 1) ensure we use fast-throwing exceptions (e.g. no stack traces) 2) can add a non-throwing variant, BUT the invalid coercion response would need to be identified by all other middleware in chain as “non-success-case”. If you have a middlware that starts a transaction and coercion fails after it, that mw should rollback in case of coercion error.

Eyal H08:09:35

Thanks @U055NJ5CC! I was referring to the backend. Do you have an example for this? (fast throwing exceptions and non-throwing variant)

ikitommi08:09:11

filling the stack trace is really slow. Coercion could have a custom Exception type, without filling the stack trace: https://www.atlassian.com/blog/archives/if_you_use_exceptions_for_path_control_dont_fill_in_the_stac

Eyal H08:09:45

Thanks. How do you set a custom exception type for the coercion

Eyal H08:09:26

What about the option to not throw at all?

ikitommi08:09:23

> BUT the invalid coercion response would need to be identified by all other middleware in chain as “non-success-case”. If you have a middlware that starts a transaction and coercion fails after it, that mw should rollback in case of coercion error.

ikitommi08:09:52

need to solve that first. there is no non-throwing-raise in ring spesification, have to invent such.

ikitommi08:09:42

the stackless custom coercion exception needs to be added to reitit itself, Issue/PR welcome.

Eyal H08:09:18

Yes, adding a middlware that identifies the failure is not an issue. Isn't there an option in reiit where I can customize the coerce middleware not to throw the excetopn, just mark it as failed on the request (for example). Then. in a separate middleware, I can check for that flag and act accordingly

ikitommi09:09:28

not yet, please write an issue, pr would be welcome too.

Eyal H09:09:44

Ok, thanks a lot

ikitommi07:09:13

async-ring doesn’t have to throw, you can just create an exception (without the stack trace) and pass it into to raise handler => just an object.

ikitommi08:09:33

did you run the coercion flamegraphs with malli? happy to optimize the perf on that, Some things in mind: 1. derive optimized Jackson parser from malli schemas => parsing & coercion in single step, we can select just the data needed => 3+ steps less in transformations, less garbage 2. control reitit coercion key keywordization from coercion impl => now re-keywordizating all map-bodies 3. don’t throw on error, optimized responses