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

Proposal: Status Code Error Enums #27

Open
jasnell opened this issue Jun 6, 2019 · 6 comments
Open

Proposal: Status Code Error Enums #27

jasnell opened this issue Jun 6, 2019 · 6 comments

Comments

@jasnell
Copy link
Collaborator

jasnell commented Jun 6, 2019

For errors, any negative value should be considered an error, with multiple negative values permitted. That would obviously mean not using an enum for status, and instead using constants... e.g.

#define BOB_ERR_{whatever} -{some integer}
#define BOB_ERR_END 0
#define BOB_ERR_CONTINUE 1
@jasnell
Copy link
Collaborator Author

jasnell commented Jun 6, 2019

Another suggestion tho it makes the protocol slightly more complicated. QUIC uses a nice pattern where errors can actually be namespaced. It allows us to avoid needing to reserve error ranges. For instance:

#define BOB_ERR_FAMILY_BOB 0  // Status codes common to all Bob cases
#define BOB_ERR_FAMILY_APP 1  // Status codes specific to the Bob application

#define BOB_ERR_FAIL -1
#define BOB_ERR_END 0
#define BOB_ERR_CONTINUE 1

struct BobError {
  int code;
  int family;
  BobError(
      int code_ = BOB_ERR_END,
      int family_ = BOB_ERR_FAMILY_BOB) :
      code(code_), family(family_) {}
};

// Usage
BobError error();
BobError error(BOB_ERR_CONTINUE);
BobError error(-100, BOB_ERR_FAMILY_APP);

Provides a bit more flexibility over time.

@jasnell jasnell changed the title Status Code Error Enums Proposal: Status Code Error Enums Jun 6, 2019
@Fishrock123
Copy link
Owner

@jasnell Can you elaborate on the purpose?

Keep in mind the actual error is a different property than the status. The Status determines specifically the flow, but any component could, once reading that the states was an error, do something different depending on what the error was?

@jasnell
Copy link
Collaborator Author

jasnell commented Jun 6, 2019

Well, I can illustrate by pointing to QUIC at least. With QUIC, there are generally three kinds of errors: Protocol, Crypto, and Application. The Crypto errors are a reserved range of Protocol errors so I'll ignore those for now. Simply, A protocol error with code -1 has different meaning that an application error with code -1; with the former being defined by the QUIC spec, and the latter being defined by the application spec (for instance HTTP/3). So, Protocol error -215 might be "Invalid QUIC Packet Format" while Application error -215 might be "Invalid HTTP Header format". The purpose of differentiating in bob would be to allow more granular error conditions to flow through the bob protocol rather than having to rely on additional out-of-band means for propagating.

@Fishrock123
Copy link
Owner

I suppose I mean more, how do you envision those being handled in a series of stream components?

@jasnell
Copy link
Collaborator Author

jasnell commented Jun 6, 2019

in the protocol, all errors are just pass-through terminal states. Rather than a single value propagating up, you have the pair propagating up. If there are any bob protocol specific actions to take, those would only be specific to the BOB_ERR_FAMILY_BOB errors.

@Fishrock123
Copy link
Owner

Hmmm, I'm not sure yet.

I think it would be good to design the system to be able to be expanded to such a use-case but perhaps not fully support it, at least in "early" iterations.

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

No branches or pull requests

2 participants