Skip to content

Commit bc3963d

Browse files
committed
Added error handling
1 parent db340b1 commit bc3963d

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

RFCs/0002-pluggable-discovery.md

+75-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ All the commands listed in this specification must be implemented in the discove
4848

4949
After startup, the tool will just stay idle waiting for commands. The available commands are: `HELLO`, `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`.
5050

51+
The discovery must not introduce any delay in the protocol and must respond to all commands as fast as possible.
52+
5153
#### HELLO command
5254

53-
`HELLO` is the **first command that must be sent** to the discovery to tell the name of the client/IDE and the version of the pluggable discovery protocol that the client/IDE supports.
55+
`HELLO` **must be the first command sent** to the discovery to tell the name of the client/IDE and the version of the pluggable discovery protocol that the client/IDE supports.
5456
The syntax of the command is:
5557

5658
`HELLO <PROTOCOL_VERSION> "<USER_AGENT>"`
@@ -92,6 +94,18 @@ The `START` command initializes and start the discovery internal subroutines. Th
9294
}
9395
```
9496

97+
If the discovery could not start, for any reason, it must report the error with:
98+
99+
```JSON
100+
{
101+
"eventType": "start",
102+
"error": true,
103+
"message": "Permission error"
104+
}
105+
```
106+
107+
The `error` field must be set to `true` and the `message` field should contain a description of the error.
108+
95109
#### STOP command
96110

97111
The `STOP` command stops the discovery internal subroutines and possibly free the internally used resources. This command should be called if the client wants to pause the discovery for a while. The response to the command is:
@@ -103,6 +117,18 @@ The `STOP` command stops the discovery internal subroutines and possibly free th
103117
}
104118
```
105119

120+
If an error occurs:
121+
122+
```JSON
123+
{
124+
"eventType": "stop",
125+
"error": true,
126+
"message": "Resource busy"
127+
}
128+
```
129+
130+
The `error` field must be set to `true` and the `message` field should contain a description of the error.
131+
106132
#### QUIT command
107133

108134
The `QUIT` command terminates the discovery. The response to `QUIT` is:
@@ -114,7 +140,7 @@ The `QUIT` command terminates the discovery. The response to `QUIT` is:
114140
}
115141
```
116142

117-
after this output the discovery exits.
143+
after this output the discovery exits. This command is supposed to always succeed.
118144

119145
#### LIST command
120146

@@ -181,11 +207,42 @@ The `LIST` command performs a one-shot polling of the ports. The discovery shoul
181207

182208
Some discoveries may require some time to discover a new port (for example network protocols like MDNS, Bluetooth, etc. requires some seconds to receive the broadcasts from all available clients) in that case is fine to answer with an empty or incomplete list.
183209

210+
If an error occurs and the discovery can't complete the enumeration is must report the error with:
211+
212+
```JSON
213+
{
214+
"eventType": "list",
215+
"error": true,
216+
"message": "Resource busy"
217+
}
218+
```
219+
220+
The `error` field must be set to `true` and the `message` field should contain a description of the error.
221+
184222
#### START_SYNC command
185223

186-
The `START_SYNC` command puts the tool in "events" mode: the discovery will send `add` and `remove` events each time a new port is detected or removed respectively.
224+
The `START_SYNC` command puts the tool in "events" mode: the discovery will send `add` and `remove` events each time a new port is detected or removed respectively. If the discovery goes into "events" mode successfully the response to this command is:
225+
226+
```JSON
227+
{
228+
"eventType": "start_sync",
229+
"message": "OK"
230+
}
231+
```
187232

188-
If the CLI is used in command-line mode (`arduino-cli board list` command) then we need a one-shot output and we can run the discoveries with the `LIST` command instead. Note that some discoveries may not be able to `LIST` ports immediately after the launch (in particular network protocols like MDNS, Bluetooth, etc. requires some seconds to receive the broadcasts from all available clients).
233+
After this message the discoery will send `add` and `remove` event asyncronoushly (more on that later). If an error occurs and the discovery can't go in "events" mode the error must be reported as:
234+
235+
```JSON
236+
{
237+
"eventType": "start_sync",
238+
"error": true,
239+
"message": "Resource busy"
240+
}
241+
```
242+
243+
The `error` field must be set to `true` and the `message` field should contain a description of the error.
244+
245+
If the CLI is used in command-line mode (for example the `arduino-cli board list` command) then we need a one-shot output and we can run the discoveries with the `LIST` command instead of using `START_SYNC`. Note that some discoveries may not be able to `LIST` ports immediately after the launch (in particular network protocols like MDNS, Bluetooth, etc. requires some seconds to receive the broadcasts from all available clients).
189246

190247
If the CLI is running in daemon mode, ideally, all the installed discoveries should be started simultaneously in “event mode” (with `START_SYNC`) and the list of available ports should be cached inside the CLI daemon.
191248

@@ -227,6 +284,20 @@ The content is straightforward, in this case only the `address` and `protocol` f
227284

228285
If the information about a port needs to be updated the discovery may send a new `add` message for the same port address and protocol without sending a `remove` first: this means that all the previous information about the port must be discarded and replaced with the new one.
229286

287+
#### Invalid commands
288+
289+
If the client sends an invalid or malformed command, the discovery should answer with:
290+
291+
```JSON
292+
{
293+
"eventType": "command_error",
294+
"error": true,
295+
"message": "Unknown command XXXX"
296+
}
297+
```
298+
299+
#### Reference implementations
300+
230301
A demo tool is available here:
231302
https://github.com/arduino/serial-discovery
232303

0 commit comments

Comments
 (0)