Errors and reasons
The server answers a failed RPC with a gRPC status code. For four conditions it also sends
the trailing metadata entry linuxcnc-grpc-reason, so a client can act on the condition
without parsing the message. A 1.0 server sends no such entry.
A command LinuxCNC or the server refuses is not a gRPC error: SendCommand answers normally
with RCS_ERROR and a message, for example “Too many commands are waiting; the command was
not sent” with not_sent true. RCS_ERROR from SendCommand
lists the causes and when not_sent makes a retry safe.
Reasons
| Reason | Code | Meaning | RPCs | What to do |
|---|---|---|---|---|
not-connected | UNAVAILABLE | The server is running but has not connected to LinuxCNC yet. | GetStatus, SendCommand, WaitComplete, StreamStatus, StreamErrors, ResolveFile, GetMachineConfig. | Try again later; the server connects by itself when LinuxCNC starts. |
linuxcnc-gone | UNAVAILABLE | The LinuxCNC the server was attached to has shut down or been restarted, and the server is stopping. | The seven RPCs above and every HAL RPC; open streams end with it. | Try again later; a supervisor starts a new server, which connects to the new LinuxCNC. |
status-unreadable | UNAVAILABLE | LinuxCNC’s task is stopped while it holds the status buffer; LinuxCNC is still connected. | GetStatus, GetMachineConfig, ResolveFile. | Try again after a short pause. |
ini-not-read-in-cycle | FAILED_PRECONDITION | The server has not read LinuxCNC’s INI file because the machine has been in cycle since it connected. | GetMachineConfig. | Call again once the machine is idle. |
Some checks come before the connection check, so they answer the same, connected or not,
and without a reason: a stream or WaitComplete over the server’s
limit answers RESOURCE_EXHAUSTED; WatchValues
with no names or too many answers INVALID_ARGUMENT; StreamErrors on a server started with
--error-channel off answers FAILED_PRECONDITION; ResolveFile with a bad name answers
INVALID_ARGUMENT; and a SendCommand that is not a stop, over the
command limit, answers RCS_ERROR with not_sent true. See
Starting before LinuxCNC.
When LinuxCNC is gone, a stop is still sent with the command helper; with
--in-process-commands it is refused with linuxcnc-gone like every other command. A
WaitComplete in progress answers RCS_ERROR. A SendCommand still waiting for its turn
answers RCS_ERROR with not_sent true. See
When the server finds its LinuxCNC gone.
While the status is unreadable, health stays SERVING and GetServerInfo reports
linuxcnc_connected true. StreamStatus sends nothing and WaitComplete keeps waiting.
Commands are still sent, except home or unhome of all joints and those whose joint or spindle
number is checked against the machine: they get RCS_ERROR with not_sent true. If the task
died while it held the buffer, the server answers linuxcnc-gone instead. See
A task stopped while it holds the status.
UNAVAILABLE without a reason
An UNAVAILABLE with no linuxcnc-grpc-reason entry is one of three things:
- LinuxCNC’s Python module raised an error while the server read the status in
GetStatus,StreamStatus,ResolveFileorGetMachineConfig. The message starts withLinuxCNC unavailable:. This is rare. - The server is shutting down; a call still open ends this way.
- The connection to the server failed: the server is not running, or the network is down.
A missing entry therefore does not prove the server was reached.
Status codes
| Code | When |
|---|---|
UNAVAILABLE | One of the reasons above, a LinuxCNC error during a status read, a server shutting down, or the transport. |
FAILED_PRECONDITION | StreamErrors with --error-channel off, or GetMachineConfig with ini-not-read-in-cycle. |
INVALID_ARGUMENT | A file RPC got an invalid name (empty, a null byte, outside the NC files directory, a symbolic link loop), an empty or too large upload, a negative offset or max_bytes, or a path that is not a regular file. |
INVALID_ARGUMENT | WatchValues got no names, too many names, or a name it cannot watch. |
NOT_FOUND | A file or directory does not exist, or the health Check names a service the server does not have. |
ALREADY_EXISTS | UploadFile with fail_if_exists set found the file already there. |
ABORTED | The file changed while ReadFile was reading it; start again from offset 0. |
RESOURCE_EXHAUSTED | The server’s limit of streams and WaitComplete calls in progress is reached; try again when one has ended (limits). |
RESOURCE_EXHAUSTED | gRPC refused a request larger than the 11 MiB receive limit. |
UNIMPLEMENTED | The server is older than the RPC, for example GetServerInfo on a 1.0 server (identity). |
UNIMPLEMENTED | The health Watch is over the server’s limit of open watchers; poll Check instead (health). |
DEADLINE_EXCEEDED | The client’s deadline passed. A command already sent is not withdrawn, and a stop still waiting for its turn is still written (stops). |
INTERNAL | An unexpected server-side failure, such as a file system error or a failed HAL read. |
Reading the reason in Python
import grpc
from linuxcnc_pb import linuxcnc_pb2, linuxcnc_pb2_grpc
channel = grpc.insecure_channel("127.0.0.1:50051")
stub = linuxcnc_pb2_grpc.LinuxCNCServiceStub(channel)
try:
status = stub.GetStatus(linuxcnc_pb2.GetStatusRequest(), timeout=5)
except grpc.RpcError as error:
reason = dict(error.trailing_metadata() or ()).get("linuxcnc-grpc-reason")
if reason in ("not-connected", "linuxcnc-gone", "status-unreadable"):
print(f"LinuxCNC is not available right now ({reason}); try again later")
elif error.code() == grpc.StatusCode.UNAVAILABLE:
print(f"No reason given: {error.details()}")
else:
raise