Reference/01

Output and errors

The JSON envelope, exit codes and debug tools.

Envelope

When stdout is not a terminal, every command prints one JSON document.

{ "ok": true, "command": "record show", "tool_version": "0.1.0+0123456789ab", "data": {}, "warnings": [], "elapsed_ms": 5 }
{
  "ok": false,
  "command": "record show",
  "tool_version": "0.1.0+0123456789ab",
  "error": { "code": "NOT_FOUND", "message": "...", "hint": "...", "details": {} }
}

When a command takes a value from a project file, the document also has a project field with the file and the values.

tool_version identifies the build that made the document: the version, then + and the git commit. A build from a changed source tree ends with .dirty. A build without git has the version only. esx --version prints the same data:

esx --version
# esx 0.1.0 (commit 0123456789ab, dirty)

Use --format jsonl to print list items one per line. Use --pretty to indent the JSON.

Lists and --limit

A command that gives a list has a --limit option. The value 0 means no limit. When the limit cuts a list, the envelope has a warning with the code LIST_TRUNCATED, the name of the list, and the numbers shown and total.

esx search Fallout4.esm --sig WEAP --edid '(?i)pipe' --limit 2
# matched 9, shown 2, warning LIST_TRUNCATED
esx search Fallout4.esm --sig WEAP --edid '(?i)pipe' --limit 0
# matched 9, shown 9
Command Default limit
search 500
record refs, plugin check, plugin diff, release check 1000
debug scan 200
debug roundtrip 100
strings dump 100000
plugin records, plugin conflicts, archive list, resource list No limit

plugin check stops at its limit, so its warning has no total.

Exit codes

Code Meaning
0 Success.
2 Usage error.
3 Not found.
4 Invalid argument or value.
5 I/O or format error.
6 Not allowed or not supported.
7 Issues found.
70 Internal error.

Error reasons

Some errors have a stable reason in error.details.reason. A program that calls esx can branch on it. These three reasons come from each command that writes a file:

Reason Code Exit code Condition Other details
OUTPUT_EXISTS NOT_ALLOWED 6 -o names a file that exists, and --overwrite is not given. A save over the plugin that the command loaded is not this error. path
GAME_FOLDER_WRITE NOT_ALLOWED 6 The file to write is in a game folder, and --allow-game-folder is not given. path, game_folder
PLUGIN_DAMAGED FORMAT 5 The plugin to save has a load issue with the severity error. file, issues (each with offset, severity, code, message)
{"ok":false,"command":"plugin resave","tool_version":"0.1.0+0123456789ab","error":{"code":"NOT_ALLOWED",
 "message":"build/MyMod.esp exists; nothing was written",
 "hint":"give --overwrite to replace it, or give a different path with -o",
 "details":{"reason":"OUTPUT_EXISTS","path":"build/MyMod.esp"}},"elapsed_ms":13}

See Save rules.

One reason comes from nif prune:

Reason Code Exit code Condition Other details
NIF_BLOCK_UNMAPPED UNSUPPORTED 6 The mesh has a block whose references esx does not know: a block type that no vanilla Fallout 4 mesh has, or a block that its reader did not read to the last byte. esx cannot move the blocks of this mesh. nif show and nif set still work on it. types, blocks (each with index, type, error)

See Remove unused blocks.

These reasons come from nif import:

Reason Code Exit code Condition
MODEL_NO_UV INVALID_VALUE 4 A primitive of the model has no TEXCOORD_0.
MODEL_SCALE_NOT_UNIFORM INVALID_VALUE 4 A node of the model has three different scale values.
MESH_VERTEX_LIMIT INVALID_VALUE 4 A primitive has more than 65,535 vertices. The message has the count.
MESH_JOB_INVALID INVALID_ARGUMENT 4 The job file has an unknown key, a wrong value, or a name that the model, the output or the template does not have. These also give this reason: a .bgem material path for a lighting shader, a key of a template with no template, a vertex of a skinned shape with no weight, a skin on the template shape or on the model shape only, a template shape with eye data, and a segments value that the model or the template shape cannot give: "model" for a model with no _ESX_SEGMENT or no extras.esx.segments, "template" with no template shape, "none" for a BSSubIndexTriShape of the template, and "model" or "default" for a BSTriShape of the template.
MESH_TEMPLATE_NOT_FOUND NOT_FOUND 3 The template, the collision source or the skeleton mesh of nif import is not a file of the Data folder, its archives or the folder of the job file.
MESH_BONE_LIMIT INVALID_VALUE 4 The vertices of a shape use more than 256 bones. The message has the count.
MESH_BONE_NOT_FOUND INVALID_VALUE 4 With a template: a joint of the model is not a node of the template and not a node of the mesh of the key skeleton.
MESH_TEMPLATE_SHAPE_UNMATCHED INVALID_VALUE 4 A shape of the template has no shape of the model, and unmatched is "error". The message lists the names.
MESH_SEGMENT_MIXED INVALID_VALUE 4 The three vertices of a triangle do not have one _ESX_SEGMENT value. The message has the count of such triangles. A vertex at the border of two segments must be two vertices at one place.
MESH_TWO_SOURCES INVALID_ARGUMENT 4 esx build: a project has a model in meshes/ and a mesh in an asset folder with the same output path, or two models with one output path. Remove one of the two.
MODEL_PRIMITIVE_MODE FORMAT 5 A primitive is not a triangle list.
MODEL_INDEX_RANGE FORMAT 5 A triangle names a vertex that does not exist.
MODEL_EXTENSION_UNSUPPORTED UNSUPPORTED 6 The model needs an extension that esx does not read, for example Draco compression.
MODEL_INVALID FORMAT or INVALID_VALUE 5 or 4 The file is not a glTF 2.0 file, or a value of the model is not correct: a position that is not a number, a position outside the range of half precision, an _ESX_SEGMENT value that is not the number of a part of the table, or an extras.esx.segments value that is not a table.
MODEL_IO IO 5 The model or a buffer file of the model cannot be read.

The warnings of nif import are in warnings of the envelope and in data.warnings:

Code Condition
MODEL_ATTRIBUTE_IGNORED The model has TEXCOORD_1, COLOR_1 or another attribute that the import does not use. A primitive has _ESX_SEGMENT, and its mesh has no extras.esx.segments. With a template: the model has vertex colors, a material path or a segment table that the template shape cannot hold.
MODEL_NO_NORMALS A primitive has no NORMAL. esx calculated the normals from the triangles.
MODEL_NAME_REPEATED Two nodes or shapes of the output have one name.
MESH_NO_MATERIAL A shape has no material path.
MESH_MATERIAL_NOT_FOUND With --data: the material path names no file in the Data folder or the archives of the game, or esx cannot read the file. The texture set is empty.
MESH_HALF_PRECISION Half precision moves a vertex by more than 1/32 game unit. The message has the largest distance.
MESH_WEIGHTS_LIMIT A vertex of the model has more than 4 weights. The import keeps the 4 largest and makes their sum 1. The message has the count of such vertices.
MESH_SEGMENTS_LOST A shape of the template has a segment table, the model has no table, and its triangles are not the triangles of the template. The shape has the default table of 4 segments, with each triangle in the last one.
MESH_POINT_PARENT_NOT_FOUND nif export: a parent connect point names a node that the mesh does not have. The point is below the root of the model.
MESH_ROTATION_NOT_EXACT nif export: a matrix of the mesh is not a rotation. The model has the nearest rotation.
MESH_TEMPLATE_SHAPE_UNMATCHED nif import with unmatched = "keep": a shape of the template has no shape of the model, and it stays with its geometry.

The note MESH_SHAPE_ADDED is in template.notes of the report of nif import: a shape of the model is not in the template, and the command added it with a new shader.

See Make a mesh from a model and Fill a template.

Command catalog

esx commands --format json

The catalog lists every command with its arguments and examples. Programs and AI agents can read it.

Debug a record

Use these commands when a value looks wrong:

esx debug explain MyMod.esp edid:MyWeapon
esx debug subrecords MyMod.esp edid:MyWeapon
esx debug hexdump MyMod.esp edid:MyWeapon
esx debug scan MyMod.esp
esx defs show WEAP --values

debug explain is the best first step. It prints byte offsets, sizes, hex data and every union and array decision. Add --trace to record show to include the same trace.

esx debug roundtrip decodes and encodes every record in memory. It reports byte changes and writes no plugin.