diff --git a/index.bs b/index.bs index df1582e7d..44d3e3671 100644 --- a/index.bs +++ b/index.bs @@ -122,31 +122,24 @@ EmptyParams = { *text }
 Message = (
   CommandResponse //
+  ErrorResponse //
   Event
 )
 
-CommandResponse = (
+CommandResponse = {
   id: uint,
-  ResponseData,
-)
-
-ResponseData = (
-  Error //
-  CommandResult
-)
+  value: ResultData,
+}
 
-Error = (
+ErrorResponse = {
+  id: uint / null,
   error: (
     "unknown error" /
     "unknown method" /
     "invalid argument"
   ),
   message: text,
-  stacktrace: text,
-)
-
-CommandResult = {
-  value: ResultData,
+  stacktrace?: text,
 }
 
 ResultData = (
@@ -296,9 +289,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 +483,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 +507,23 @@ 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 ErrorResponse + production in the [=local end definition=], with the id field + set to |command id|, 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. Let |response| be the result of [=serialize JSON to bytes|serializing JSON + to bytes=] given |error data|. + + 1. [=Send a WebSocket message=] comprised of |response| over |connection|.