Language

Theme authoring rules and common rejections

What 400/409/413/422/500/503 each mean, why template syntax errors return 422, and that every code has a human sentence in the backend.

In theme development "rejected" is the norm; the key is that the rejection says which cell, and what to do next. This page classifies the common rejection codes by what you are doing, and explains why some return 400, some 409 and some 422.

First, the division of labor among status codes; it is not arbitrary. A wrong request shape (missing fields, invalid payload, over size) returns 400/413; the current facts do not allow this action returns 409 (the theme is in use, the identifier is taken, the kernel version is incompatible, this version is not higher than the existing ones); the request shape is fully correct but what fails is the theme's own syntax gate, returning 422; a server-side failure returns 500; and "the facts needed to give a conclusion cannot be read" returns 503 and changes nothing. The difference between the last two is worth remembering: 500 reads like "we broke", 503 reads like "do not retry now; go fix that dependency first". The practical consequence of mixing template syntax errors into 400 is real — operations will go edit the form, and the form was never filled wrong.

Upload and install stage. An invalid package (manifest missing required cells, declarations not matching actual files, unsafe paths) returns 400 and names the file; over the size limit returns 413, with a cap of 5 MiB — the same constant serves both as the request-body ceiling and as the length check before unpacking; an identifier colliding with an existing theme returns 409; requires_kernel incompatible with this machine returns 409 — this one is good news, meaning an install result of "installed but crashing on every render" cannot happen.

Edit and save stage. The common four: THEME_FILE_NOT_DECLARED (the file you want to submit is not in the baseline manifest), THEME_FILE_NOT_EDITABLE (binary assets are visible but not clickable), THEME_VERSION_NOT_HIGHER (the version number is not higher than every version in the store; in-place edits get eaten by startup replay), THEME_TEMPLATE_INVALID (the template fails html/template, returning 422). There is also a rare THEME_FILE_SET_MISMATCH: you want to delete a file by changing the manifest — bytes still on disk while absent from the declaration is an intermediate state, so the whole batch is rejected.

Activation and publish stage. The target already being the current one returns 409 (idempotency protection, not an error); protected actions on built-in/default themes return 409; a retired theme returns 409 and tells you to pick the built-in default theme; a theme referenced by the current or kept snapshots cannot be deleted, returning 409, and when the reference relationship cannot be read it returns 503 without moving a byte — not reading the facts does not mean there are no facts.

Every code has a human sentence in the backend. Server error codes to UI copy are an explicit table, with a reconciliation running on the closed set on the output side: adding a new error code without the Chinese and English copy turns the test red on the spot. The reason for this criterion is stated plainly — missing one is not "one Chinese sentence short"; it is operations seeing only an English original and guessing the next step from that sentence. The order in the response is "site copy first + server original in parentheses": sending only the original turns the Chinese UI into English, and sending only the site copy loses "which cell exactly".

Four practical suggestions for authors. One, read the interface self-description (GET /api/v1/themes/api) before changing templates; field names and meanings are generated from server-side data structures, and a field absent from the self-description does not exist. Two, run the template through Go's template syntax locally, which is faster than trial and error in the editor, because 422 only tells you it did not pass; it will not fix it for you. Three, bump the version number on every save; do not expect to overwrite the same version — that is the only shape that "changes and then vanishes". Four, remember to publish after changing styles, otherwise production is still the old snapshot's version.