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(metadata): use error codes #1904

Merged
merged 5 commits into from
Mar 12, 2024
Merged

Conversation

danisharora099
Copy link
Collaborator

Problem

Protocols currently use different pattern to handle errors.
Light push uses error code while filter uses exception.

It is best for the user if a common pattern is used across the API.
Also, there is an opportunity to re-use error code across the codebase and have similar pattern on the user side to handle them

Solution

  • Use the same enum that is used for LightPush, for Metadata
  • Rename SendError to ProtocolError to be more accomodating

Notes

Contribution checklist:

  • covered by unit tests;
  • covered by e2e test;
  • add ! in title if breaks public API;

@danisharora099 danisharora099 requested a review from a team as a code owner March 11, 2024 14:20
Copy link

github-actions bot commented Mar 11, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 185.4 KB (+0.09% 🔺) 3.8 s (+0.09% 🔺) 15.2 s (+0.56% 🔺) 18.9 s
Waku Simple Light Node 185.42 KB (+0.08% 🔺) 3.8 s (+0.08% 🔺) 21.7 s (+105.32% 🔺) 25.4 s
ECIES encryption 22.89 KB (0%) 458 ms (0%) 6 s (+115.19% 🔺) 6.5 s
Symmetric encryption 22.34 KB (0%) 447 ms (0%) 3.6 s (-2.28% 🔽) 4.1 s
DNS discovery 73.78 KB (0%) 1.5 s (0%) 12.9 s (+60.2% 🔺) 14.4 s
Peer Exchange discovery 75.27 KB (0%) 1.6 s (0%) 10.1 s (+18.9% 🔺) 11.7 s
Local Peer Cache Discovery 69.07 KB (0%) 1.4 s (0%) 11.7 s (+55.52% 🔺) 13.1 s
Privacy preserving protocols 39.96 KB (0%) 800 ms (0%) 7 s (-18.95% 🔽) 7.8 s
Waku Filter 20.11 KB (0%) 403 ms (0%) 4.3 s (+39.07% 🔺) 4.8 s
Waku LightPush 115.49 KB (0%) 2.4 s (0%) 10.4 s (+49.05% 🔺) 12.7 s
History retrieval protocols 19.34 KB (0%) 387 ms (0%) 5.7 s (+56.93% 🔺) 6.1 s
Deterministic Message Hashing 4.96 KB (0%) 100 ms (0%) 198 ms (+7.6% 🔺) 297 ms

ShardingParams
} from "./protocols.js";

export type QueryResult =
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: it should be generic and should cover PreparePushMessageResult as well

proposed structure:

// Most common generic to cover potential cases in future
type Result<T, E> =
  | {
      query: T;
      error: null;
    }
  | {
      query: null;
      error: E;
    };

export type ProtocolResult = Result<ShardInfo, ProtocolError>; // or QueryResult 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The generic should already be able to cover that. Note: this PR is only for metadata and LightPush will be handled in a separate PR. Thanks for the flag though!

Copy link
Collaborator

@weboko weboko left a comment

Choose a reason for hiding this comment

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

added some nit's

@@ -101,7 +101,7 @@ export type Callback<T extends IDecodedMessage> = (
msg: T
) => void | Promise<void>;

export enum SendError {
export enum ProtocolError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one I'd like to discuss.

This enum is used as a constant and part of runtime and not typescript compile time.
That means that in some cases @waku/interfaces should be dependencies and not devDependencies.

So far we didn't see any issues because of that and I was not able to get any in my experiments, but overall it seems to me worth making a part of @waku/core.

wdyt @waku-org/js-waku-developers ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@weboko can we track this in an issue? We can discuss this in the coming PM call, or async within the issue
cc @adklempner

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure, I wanted to bring this to discussion so that our team is aware of it

@weboko weboko mentioned this pull request Mar 11, 2024
@danisharora099 danisharora099 merged commit 1882023 into master Mar 12, 2024
9 of 10 checks passed
@danisharora099 danisharora099 deleted the feat/metadata-error-codes branch March 12, 2024 11:10
@weboko weboko mentioned this pull request Mar 12, 2024
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.

2 participants