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

Define how to respond with an error #56

Merged
merged 3 commits into from Oct 20, 2020
Merged

Define how to respond with an error #56

merged 3 commits into from Oct 20, 2020

Conversation

jgraham
Copy link
Member

@jgraham jgraham commented Sep 16, 2020

The main difficulty here is that if we get a command with an invalid id, it's
unclear what to return in the id field. This chooses to return null in that case.


Preview | Diff

@jgraham
Copy link
Member Author

jgraham commented Sep 16, 2020

This depends on #50 so we can't land it before that, but since the error parts weren't defined I made a quick PR.

Base automatically changed from cddl_refactor to master September 18, 2020 08:51
@foolip foolip changed the title Define how to response with an error Define how to respond with an error Sep 21, 2020
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
Copy link
Member

@foolip foolip left a comment

Choose a reason for hiding this comment

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

LGTM % questions and nits

index.bs Outdated Show resolved Hide resolved
index.bs Outdated

1. Issue: Form a valid JSON |errorObject| given |code|.
1. If |command id| is not a number, let |command id| be null.
Copy link
Member

Choose a reason for hiding this comment

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

Our handling of invalid id seems a bit broken/incomplete still. If the number wasn't in the CDDL uint range, should we send back that number, or null? I think null would make sense, but I don't think spec makes it so.

This algorithm ("respond with an error") is called by "handle an incoming message", but that just parses JSON and doesn't try to interpret the id member. Then we have "Match data against the remote end definition" in "process a command" which operates on the unparsed scalar value string, and that would fail if the id isn't a CDDL uint. However, it doesn't extract a known-to-be-uint id if something else in the schema didn't match.

Overall, that we both parse the message payload as JSON and interpret it per CDDL seems suspect, and probably not how one would implement this.

If fixing this in this PR is too much, then a follow-up issue would be OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, so I moved the JSON parse down into the "respond with an error" algorithm. It seems hard to eliminate the possibility of a second parse entirely at least in the spec. A real implementation could be structured so that parsing and validation were seperate steps or something. But I think this is good enough to ensure interoperable behaviour.

index.bs Show resolved Hide resolved
Copy link
Member Author

@jgraham jgraham left a comment

Choose a reason for hiding this comment

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

I ended up making a bit of a bigger change in response to the review comments so you may want to look again.

index.bs Outdated

1. Issue: Form a valid JSON |errorObject| given |code|.
1. If |command id| is not a number, let |command id| be null.
Copy link
Member Author

Choose a reason for hiding this comment

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

OK, so I moved the JSON parse down into the "respond with an error" algorithm. It seems hard to eliminate the possibility of a second parse entirely at least in the spec. A real implementation could be structured so that parsing and validation were seperate steps or something. But I think this is good enough to ensure interoperable behaviour.

index.bs Show resolved Hide resolved
The main difficulty here is that if we get a command with an invalid id, it's
unclear what to return in the id field. This chooses to return null in that case.
Copy link
Member

@foolip foolip left a comment

Choose a reason for hiding this comment

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

Looks good. Using Infra to serialize a map to JSON is an optional improvement, could just as well do it separately. You decide :)

index.bs Outdated
string containing a stack trace report of the active stack frames at the
time when the error occurred.

1. Let |response| be the result of [=serialize a map as JSON=] given |error
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Presumably we want to use "as bytes" instead.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, my bad.


7. Let |response| be a new [=map=] with the following properties:
1. Let |command id| and |value| be the two fields |result|'s data.
Copy link
Member

Choose a reason for hiding this comment

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

Alright, so this is unpacking the return value from 'Return success with (data parsed["id"], value)' elsewhere.

@jgraham jgraham merged commit 819fd0c into master Oct 20, 2020
@jgraham jgraham deleted the error_response branch October 20, 2020 14:06
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.

None yet

4 participants