Skip to content
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: registerErrorTransformer in composer #371

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented Jan 7, 2025

Proposed Changes

  • registerErrorTransformer is a new function on the composer that allow one to register functions that are used to transform errors

The main benefit is the improved error handling when composing together one group with multiple app clients. It also simplifies the error handling logic in the app client. When an AppClient is instantiated it registers the transformer to the AlgorandClient. This means errors for that app will always be properly handled, even when the method call did not come from the AppClient. These callbacks are also used on simulate, so this also closes #368.

One thing I was going back and forth on is whether these functions should transform the error or if they are expected to raise the error themselves. The main reason I went with transforming is that transformers could add supplement information to the error, which seems useful.

Keeping in draft until #365 is merged since I manually merged that in here

src/types/composer.ts Outdated Show resolved Hide resolved
src/types/composer.ts Outdated Show resolved Hide resolved
src/types/composer.ts Outdated Show resolved Hide resolved
Co-authored-by: Tristan Menzel <[email protected]>
Copy link
Contributor

@tristanmenzel tristanmenzel left a comment

Choose a reason for hiding this comment

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

The general approach looks good to me 👍

@joe-p
Copy link
Contributor Author

joe-p commented Jan 8, 2025

The problem is that since this is an error originating from an HTTP call we have no control over how granular the context we inject can be (i.e. we could inject group or the txid we waited for, but not per-transaction level details without also parsing the error) nor do we have control over the error itself. I don't think appid= is susceptible to being changed like the opcodes considering it is zero cost. While there is no guarantee it won't change, any potential change will be heavily considered. The ocpode change wouldn't have happened if it wasn't negatively impacting the network, which appid= won't do.

src/types/composer.ts Outdated Show resolved Hide resolved
src/types/composer.ts Outdated Show resolved Hide resolved
src/types/composer.ts Outdated Show resolved Hide resolved
@joe-p joe-p marked this pull request as ready for review January 24, 2025 22:00
@joe-p joe-p force-pushed the feat/composer_error_callbacks branch from d390b5c to b96eea6 Compare January 24, 2025 22:13
@joe-p
Copy link
Contributor Author

joe-p commented Jan 24, 2025

Now that #365 is merged this should be good to go. Only substantive change since last round of reviews was 68674c0

@aorumbayev
Copy link
Contributor

aorumbayev commented Jan 31, 2025

@joe-p do you consider this new functionality applicable to python utils as well? Given that the py version is up to speed with ts counterpart with v3 (which is in feedback cycle stage at the moment), makes sense to keep feature parity in mind when extending interfaces on either py or ts side.

@joe-p
Copy link
Contributor Author

joe-p commented Jan 31, 2025

Ah yes good point @aorumbayev. I could either PR into your branch next week or to reduce moving parts we can merge your PR first and then have a separate PR for this functionality.

To avoid noise in this issue just DM on slack if you have a preference, otherwise I will make a PR into your branch next week

@@ -504,6 +504,7 @@ export class AppClient {
this._appSpec = AppClient.normaliseAppSpec(params.appSpec)
this._appName = params.appName ?? this._appSpec.name
this._algorand = params.algorand
this._algorand.registerErrorTransformer!(this.handleCallErrors)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ! necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, yes. It can be removed next major release when we remove AlgorandClientInterface. See #365 (comment)

*/
export type ErrorTransformer = (error: Error) => Promise<Error>

class NonErrorTransformer extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class NonErrorTransformer extends Error {
class NonErrorTransformerError extends Error {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've renamed it to something a bit different, InvalidErrorTransformerValue which I think is a bit easier to understand

@aorumbayev
Copy link
Contributor

Ah yes good point @aorumbayev. I could either PR into your branch next week or to reduce moving parts we can merge your PR first and then have a separate PR for this functionality.

To avoid noise in this issue just DM on slack if you have a preference, otherwise I will make a PR into your branch next week

Unless there is some rush on this, might be more straightforward for you to add this after initial v3 prod release? There is still a bit of tweaks that may happen based on ongoing feedback session with DevRel. Would be significantly easier for you to introduce it once prod release is out and everything is settled. I think this should happen within 1-2 weeks (depending on how long feedback cycle takes), i can ping you as soon as prod version is out.

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.

App client simulate errors should be parsed into a LogicError
4 participants