Skip to content

feat: Add support for custom failure converters #887

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

Merged
merged 2 commits into from
Sep 26, 2022

Conversation

bergundy
Copy link
Member

Can't test with temporalite yet, tested locally against server 1.18 in the meantime. Leaving the test as is (skipped) for now since we should be getting a new temporalite release soon.

@bergundy bergundy requested review from cretz and lorensr September 24, 2022 00:27
@bergundy bergundy self-assigned this Sep 24, 2022
@@ -1,3 +1,4 @@
import { DefaultFailureConverter, FailureConverter } from '../failure';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a bit of a circular import problem if I do this in Python and it can be a bit confusing even here in TS. To have converter/data-converter.ts depend on failure.ts which depends on converter/payload-converters.ts. This is fine in TS because you are breaking this stuff out into so many files (which I don't necessarily agree with), but it's still confusing to have thing in subdir depend on thing in general dir that depends on thing back in subdir.

I think it might be clearer to not have failure.ts depend on anything from converter and move anything related to error conversion (i.e. needing error and converter stuff) into things in this directory. But if you don't want to create a converter/failure-converter.ts, no worries.

I think in Python at least, I'll have temporalio.converter.FailureConverter right next to temporalio.converter.PayloadConverter and temporalio.converter.DataConverter, and remove all temporalio.converter imports from temporalio.exceptions. Today temporalio.exceptions depends on temporalio.converter but I think I'm gonna flip that now that DataConverter will accept a FailureConverter (class). I haven't written it yet, but it makes the most sense. Thoughts welcome.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you don't want to create a converter/failure-converter.ts, no worries.

This is what I did initially and ended up moving the code into failure.ts, I can definitely move the converter code to its own file.

Copy link
Member

@cretz cretz Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you have here is fine by me if you don't mind the dependency graph it creates.

In Python I can't have DataConverter depending on a separate-package FailureConverter that depends back on the data-converter package for PayloadConverter. So I have to have the FailureConverter with the other converters.

Comment on lines 351 to 352
* It is recommended to use the {@link DefaultFailureConverter} and not attempt to customize the default implementation
* in order to maintain cross language failure serialization compatibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should explain why this is exposed at all then, and when you might need to customize it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't ever be a need for that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why is this exposed at all? If that's the case I find this comment even more confusing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give the full flexibility, we could have just exposed a boolean to decide whether or not to encode failure attributes but that would limit power users that might want to implement their own failure serialization logic

/**
* Converts an error to a Failure proto message if defined or returns undefined
*/
export function optionalErrorToOptionalFailure(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are technically backwards-incompatible alterations right? I support removing them of course and I don't expect users ever used them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

);
// Don't apply encodedAttributes unless they conform to an expected schema
if (typeof attrs === 'object' && attrs !== null) {
const { message, stack_trace } = attrs;
Copy link
Member

@cretz cretz Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fail if our attributes are not present? I don't think it should.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not fail, it will fail if the payload converter cannot convert from payload though which I think is reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 My mistake, I assumed destructuring failed on missing key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants