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
Conversation
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. |
40e0efd
to
7552be5
Compare
7552be5
to
15cd3d6
Compare
15cd3d6
to
f4d456e
Compare
There was a problem hiding this 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
|
||
1. Issue: Form a valid JSON |errorObject| given |code|. | ||
1. If |command id| is not a number, let |command id| be null. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
f4d456e
to
75ce370
Compare
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.
75ce370
to
9e8724e
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now use https://infra.spec.whatwg.org/#serialize-an-infra-value-to-a-json-string here.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
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