diff --git a/index.bs b/index.bs index df1582e7d..6dffb7757 100644 --- a/index.bs +++ b/index.bs @@ -126,7 +126,7 @@ Message = ( ) CommandResponse = ( - id: uint, + id: uint?, ResponseData, ) @@ -142,7 +142,7 @@ Error = ( "invalid argument" ), message: text, - stacktrace: text, + stacktrace?: text, ) CommandResult = { @@ -296,9 +296,9 @@ To process a command given |data|: the method property of |data|. 1. If |command| is not in the [=set of all command names=], return an - [=Error=] with [=error code=] [=unknown command=]. + [=error=] with [=error code=] [=unknown command=]. - 1. Return an [=Error=] with [=error code=] [=invalid argument=]. + 1. Return an [=error=] with [=error code=] [=invalid argument=]. Transport {#transport} @@ -490,9 +490,9 @@ To handle an incoming message given a [=WebSocket connection=] 5. Let |result| be the result of [=process a command|processing a command=] given |data|. - 6. If |result| is an [=Error=], then [=respond with an error=] given - |connection|, |result|, and |parsed|["id"], and finally - return. + 6. If |result| is an [=error=], then [=respond with an error=] given + |connection|, |parsed|["id"], and |result|'s [=error code=], + and finally return. 7. Let |response| be a new [=map=] with the following properties: @@ -514,12 +514,30 @@ To handle an incoming message given a [=WebSocket connection=]
To respond with an error given a [=WebSocket connection=] -|connection| and an [=error code=] |code|: +|connection|, |command id| and |error code|: - 1. Issue: Form a valid JSON |errorObject| given |code|. + 1. If |command id| is not a number, let |command id| be null. - 2. [=Send a WebSocket message=] comprised of |errorObject| over - |connection|. + 1. Let |error data| be a new map matching the Error production in + the [=local end definition=], with the error field set to + |error code|, the message field set to an + implementation-defined string containing a human-readable definition of the + error that occured and the stacktrace field optionally set to + an implementation-defined string containing a stack trace report of the + active stack frames at the time when the error occurred. + + 1. Set the value of id on |error data| to |command id|. + + 1. Assert: |error data| matches the CommandResponse definition in + the [=local end definition=]. + + 1. Let |response| be the result of [=serialize JSON to bytes|serializing JSON + to bytes=] given |error data|. + + 1. Let |serialized| be the result of [=serialize JSON to + bytes|serializing JSON to bytes=] given |response|. + + 1. [=Send a WebSocket message=] comprised of |serialized|| over |connection|.