-
Notifications
You must be signed in to change notification settings - Fork 43
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
[http-remoting] Serialize Conjure error parameters to JSON rather than with Objects.toString() #1812
Comments
@iamdanfox the wire format docs claims errors should be serialized using the JSON format, probably including errors. did you already have a plan here? |
What's the path forward here? conjure-typescript generates code that follows the spec, but won't be able to deserialize errors produced by conjure-java: https://github.com/palantir/conjure-typescript/blob/develop/src/commands/generate/__tests__/resources/errors/primitiveError.ts. I'm trying to figure out what to do in conjure-rust. It seems like there are a couple of options:
|
I'd prefer to keep the conjure error parameters as plain strings (i.e. a spec update), to discourage people from putting lots of deeply-nested information in their errors. I think we should steer them towards union response types instead. Conjure errors have been quite tricky so far - for java clients, the ergonomics are pretty bad - you don't have any typed way of differentiating which error you received or what values it contained. There's also no enforcement for which endpoints will return which errors, so an exhaustive visitor becomes a bit impractical. More importantly, I'm concerned about how to promote backwards compatiblity if users invest lots of effort in defining really detailed Conjure errors. The scenario I want to avoid is:
In this scenario, the frontend's really detailed error handling probably stops working. If people start relying on these params, does this mean adding a new error type actually results in a functionality regression from a users point of view? How can frontend devs pre-empt this without compiler support. Are frontend devs really supposed to just react to constant reports of regressions in error-handling? In summary, I'd prefer to keep the conjure error params as plain strings because I think expanding them to deeply nested JSON might have unintended consequences for API design and result in harder to maintain codebases further down the line. |
I thought the entire purpose of the new error system was so that clients could introspect into them and e.g. have localized templates of the various error conditions. If clients aren't supposed to understand anything about the contents of the errors, then why are we parameterizing them at all? |
I agree that it feels a bit contradictory. At the very least the current implementation is faulty. @iamdanfox, instead of breaking the API what about introducing a new field ( |
Caught up offline with @carterkozak and @iamdanfox to discuss a way forward on this. We arrived at there being two issues with service exceptions in Java land:
We decided that we could solve both issues at once by changing the generated error bindings. The new error bindings would have distinct client and server side types, extending from We would hide all of these changes behind a Unfortunately, we aren't able to prioritize this work right now, so in the short term this problem won't be going away. |
It's ugly, but typescript code is now starting to handle this by parsing the Objects.toString() back out to a typescript array, like this:
I intend to continue using this pattern until conjure-java follows the wire spec. |
The problem is the It should instead be done with an ObjectMapper |
Currently in Java implementation error parameters are serialized with
Objects.toString()
(seeSerializableError.forException(ServiceException exception)
).This leads to different formatting of the same error depending on the language used for the error implementation.
I suggest serializing parameters (safe/unsafe error arguments) as JSON - this representation is consistent across languages because parameters are Conjure types.
This way it is also possible to deserialize parameter back into proper Conjure type.
Posting here given this should be expected behavior for all Conjure implementation.
The text was updated successfully, but these errors were encountered: