Skip to content

Exit codes ​

Scripts can distinguish "wrong password" from "corrupt file" — a precision the graphical interface cannot offer.

CodeMeaningTypical trigger
0Success—
1General errorFile missing, read or write failure
2Usage errorMisspelled option, or using --password
3Wrong password / no matching slotdecrypt or cat with a bad password
4File corrupt or tampered withAEAD authentication failure, content hash mismatch
5Unsupported format versionOpening a newer format with an older omy
6Missing shardsIncomplete shards without --ignore-missing-shards
7Insufficient permissionsNo rights on the target path
8Cancelled by the userDeclined an interactive confirmation

Measured behaviour ​

The following comes from actual runs. Note that verify and decrypt return different codes for a wrong password:

CommandSituationExit code
omy decrypt --password-file wrong.txt f.omyWrong password3
omy cat --password-file wrong.txt f.omyWrong password3
omy verify --password-file wrong.txt f.omyWrong password4
omy info nosuch.omyFile missing1
omy encrypt --password x f.txtPlaintext password flag2
omy verify --password-file right.txt f.omyNormal0

verify returns 4, not 3, for a wrong password

verify answers the question "is this file intact". It attempts decryption and compares the content hash; with the wrong password it cannot produce the right content, so it reports a verification failure (4), noting in a warning that the real cause was no matching key slot.

So the exit code of verify is not a reliable way to test whether a password is correct. Use decrypt --verify-only, which returns 3 for a wrong password.

Exit codes for remote and virtual commands ​

remote subcommands reuse these codes, with their own breakdown:

SituationExit codeNotes
Usage error on remote / remote telegram / remote virtual2from clap
General remote failure (unreachable, read/write error, telegram check down)1lets scripts tell it apart from "bad invocation" (2)
Wrong password for an encrypted Telegram place3TG_PLACE_WRONG_PASSWORD
Wrong remote virtual password3VIRTUAL_WRONG_PASSWORD
An interactive confirm on remote virtual place remove answered "no"8same as file commands
Other remote virtual failure1see the VIRTUAL_* structured codes below

remote virtual errors are structured: --json puts a code in error.code such as VIRTUAL_LOCKED (encrypted place, no password supplied), VIRTUAL_WRONG_PASSWORD (wrong password = 3), VIRTUAL_NOT_ENCRYPTED, VIRTUAL_NO_SUCH_PLACE — match that, not the localized message.

When connecting to a remote place fails (ls / upload / download / copy / decrypt / cache pin and friends), --json puts a structured TG_* code in error.code:

error.codeExit codeMeaning
TG_PLACE_WRONG_PASSWORD3A place password was supplied but cannot unlock the encrypted Telegram place
TG_PLACE_PASSWORD_REQUIRED1Encrypted place, auto-unlock by the machine key failed, and there is no TTY nor password channel (scripts: use --password-*)
TG_PLACE_LOCKED1Place is encrypted and stayed locked (no password given); prompts for a password channel
TG_NO_SESSION1No usable Telegram session for this place; run telegram login first
TG_SESSION_EXPIRED1Session is unauthorized / expired; log in again
TG_CONNECT_NO_PROXY1Direct connection failed and no proxy is configured
TG_SESSION_UNREADABLE1The session file could not be read
TG_CONNECT_FAILED1Any other connection failure

WebDAV places never produce these: they need no on-the-spot place password.

Telegram offline place operations (encrypt / unlock / lock / decrypt / targets / forward / search) always exit 1 on error and are distinguished by a stable bracket prefix in the message: [tg_unlock_wrong] wrong password, [tg_no_protector] no credential store, refusing plaintext, [tg_not_encrypted] place not encrypted, [tg_no_session] no session yet, [tg_cross_chat] forward entries from different chats. Match the prefix, not the exit code. This is a separate vocabulary from the TG_* table above: those offline ops print a human-readable bracket prefix when they transform the on-disk session envelope, whereas the TG_* codes are machine-readable, land in --json error.code, and fire when a real connection is being established.

Using them in scripts ​

bash
omy decrypt --password-stdin archive.omy < pw.txt
case $? in
  0) echo "ok" ;;
  3) echo "wrong password" ;;
  4) echo "corrupt or tampered" ;;
  6) echo "missing shards" ;;
  *) echo "other error" ;;
esac

PowerShell:

powershell
& omy decrypt --password-file pw.txt archive.omy
switch ($LASTEXITCODE) {
    0 { 'ok' }
    3 { 'wrong password' }
    4 { 'corrupt or tampered' }
    default { "other error ($LASTEXITCODE)" }
}

With --json ​

--json writes structured error information to standard output:

json
{
  "error": {
    "code": "GENERAL_ERROR",
    "exit_code": 1,
    "message": "读取 note.omy 失败"
  }
}

code is always an English constant

error.code does not change with interface language (WRONG_PASSWORD, GENERAL_ERROR and so on), whereas message is localized human-readable text.

Scripts should match code or the exit code, not message — the latter varies with language settings and versions.

The fields of info --json are part of a stable contract and feed straight into jq:

bash
omy --json info file.omy | jq -r '.cipher, .chunk_size, .plaintext_size'
# chacha20-poly1305
# 262144
# 9670

omy-core / omy-net are MIT OR Apache-2.0, omy-media is LGPL-2.1+, omy-cli / omy-gui are GPL-3.0+.