Exit codes and errors

What a castle command's exit status and error codes mean in plain words, and what to do next when your agent or a script hits one.

When a castle command ends, it leaves a number called the exit status. When it fails, it also gives an error code and a hint, which is the next thing to try. Your agent reads these for you. This page is for when you want to know what it was reading.

Exit status

Status Means
0 It worked.
1 It ran and failed, or the answer was no.
2 You (or your agent) got the command wrong. Nothing was sent.
3 The device is the problem: not found, more than one match, not running or busy.
4 Something is missing: a prerequisite, a license, or a thing this device can’t do.
5 Access: agents are off, or this device’s level doesn’t allow it.
6 It timed out, was interrupted or was cancelled.

castle exec ends with the command’s own status. When Castle itself fails, exec uses 124 (the command timed out), 125 (Castle did not finish) and 130 (you stopped it).

With --json a failure shows its code, a message and a hint, and whether anything reached the device: no (safe to repeat), unknown (look at the device before you repeat a change) or yes (it ran and failed).

Codes you may meet

Code What it means and what to do
AGENTS_OFF Agents are off for all of Castle. Turn them on in Settings › Agents. See Agents are off.
AGENT_ACCESS_OFF Agents are off for this one device. Change its level from Can’t use in the device’s Settings › Agents. See Agents are off.
DEVICE_BUSY Most often, two Macs already run: turn one off. Otherwise the message says what is busy. It is never about memory or disk. See Two Macs are already running.
UNSUPPORTED_CAPABILITY This device can’t do that. The hint says what it can.
PAUSE_UNSUPPORTED This system can’t pause yet. Leave it running.
AGENT_LEVEL The device is set to Can use, which doesn’t allow delete, reset or roll back. You can change the level in the device’s settings if you want an agent to do that.
ANOTHER_AGENT_ON_IT Another agent is on the device. Your agent tells you, and you decide.
LONGEST_HOLD The agent asked to hold the device longer than you allow. It should ask for less.
INVALID_ARGS The command was wrong, so nothing was sent. A bare castle use lists the ready devices.
AMBIGUOUS_MATCH More than one thing on screen matched. Pick one.
STALE_REF The screen changed. Look again.
SCREEN_SIZE_CHANGED The screen changed size. Take a new screenshot, then act.
SCREEN_LOCKED The phone is locked. Ask the person to unlock it.
GUEST_UNREACHABLE The device is not reachable. See Castle cannot reach this device.
NETWORK_FAILED The device’s own network failed. See A device can’t reach the internet.
CONFLICT_EXISTS Already there. Add --overwrite or choose another name.
SERVICE_MISMATCH Castle’s helper is a different build. Run castle service restart.

Two answers that look like trouble are not errors, and exit with 0:

  • waiting. The system you asked for needs you to agree to its maker’s terms in Castle. Your agent tells you, and asks again once you have said yes.
  • declined. You said no to those terms. Your agent should not ask again.

If you are stuck

Copy the message and the code, and get support.

Last updated

View as Markdown