Skip to content

Error Codes Reference

Canonical reference for all error codes emitted by the schema package. Codes use dotted-lowercase naming: category.subject.specifier for hierarchical filtering.

How to consume

Go (programmatic)

go
import (
    "errors"
    "github.com/fastschema/fastschema/schema"
)

err := mySchema.Validate()
if err != nil {
    // Walk the typed batch
    var batch *schema.SchemaErrors
    if errors.As(err, &batch) {
        for _, fe := range batch.FieldErrors {
            fmt.Printf("[%s] field=%s message=%s\n", fe.Code, fe.Field, fe.Message)
        }
        // Filter by code
        if batch.HasCode(schema.CodeFieldTypeInvalid) {
            // ...
        }
    }

    // Walk individual entries via standard library Unwrap chain
    var fieldErr *schema.FieldError
    if errors.As(err, &fieldErr) {
        // first matching FieldError
    }
}

REST / JSON

Validation errors at POST /schema and similar endpoints return HTTP 422 with structured payload:

json
{
  "code": "422",
  "message": "schema validation failed",
  "data": {
    "schema": "post",
    "field_errors": [
      {
        "code": "field.type.invalid",
        "field": "status",
        "message": "field type 'enmu' is not recognized"
      },
      {
        "code": "schema.label_field.not_found",
        "message": "label_field 'foo' is not a string/text field; available: title, body"
      }
    ]
  }
}

Frontend / API consumers should:

  1. Read data.schema for the affected schema name.
  2. Iterate data.field_errors[] for per-field issues.
  3. Map each code to a localized/help message via your own dictionary (codes are stable; messages may evolve).

Type model

TypeUse caseSchema context
FieldErrorper-field error inside a Schema.Validate() batchsupplied by enclosing SchemaErrors
SchemaErrorcross-schema, builder-level, or standalone errorexplicit on the error
SchemaErrorsbatch wrapper from Schema.Validate()yes (Schema field)
BuilderErrorsaggregation across multiple schemas at build timeeach entry sets its own

SchemaErrors.Unwrap() []error enables stdlib errors.As traversal of individual entries.

Codes by category

schema.* — schema-level errors

CodeDescription
schema.name.requiredschema is missing 'name' property
schema.label_field.requiredschema is missing 'label_field' property
schema.namespace.requiredschema is missing 'namespace' property
schema.label_field.not_foundlabel_field references a field that does not exist (or is not string/text); Message lists available alternatives
schema.label_field.system_schemasystem schema (user, role, file) has a fixed label_field; assigning another value is invalid
schema.primary_field.not_founddeclared primary_field references a field that does not exist
schema.primary_field.requiredschema has no primary key field (no id, no primary_field)
schema.io.read_errorschema directory read failed (wraps underlying IO error in Cause)
schema.init.unknownunrecognised error escaped a stage of Schema.Init; wraps the underlying error in Cause

field.* — field-level errors

CodeDescription
field.name.requiredfield at the given index is missing name
field.type.invalidfield declares a type identifier that is not recognized
field.type.missingfield has TypeInvalid (no type set)
field.type.parse_errorJSON unmarshalling encountered an unknown type identifier
field.enum.requiredenum field is missing the enums array
field.relation.requiredrelation field is missing the relation object
field.relation.schema.requiredrelation.schema not set
field.relation.type.requiredrelation.type not set or invalid (must be o2o, o2m, or m2m)
field.relation.field.requiredrelation.field not set
field.not_foundfield lookup by name failed within a known schema
field.file.schema.requiredfile field needs an owning schema name during initialization
field.setter.compile_errorfield's setter expression failed to compile (wraps expr.Compile error in Cause)
field.getter.compile_errorfield's getter expression failed to compile (wraps in Cause)

relation.* — cross-schema / FK errors

CodeDescription
relation.target.not_foundrelation.schema references a schema that is not defined
relation.back_ref.missingback-reference field not found on the target schema (or does not point back correctly)
relation.fk.target.not_foundforeign-key target field not found on target schema
relation.fk.clone_failedforeign-key field clone failed (internal)
relation.config.missingfield has type: relation but no relation configuration

builder.* — builder-level errors

CodeDescription
builder.schema.duplicatesystem schema declared more than once
builder.schema.not_foundrequested schema not found in builder; Message lists available
builder.schema.primary_key.missingschema is missing a primary-key field at build time
builder.relation.not_m2mattempted to create an m2m junction for a non-m2m relation
builder.junction_field.create_failedjunction-field creation failed (internal)

Out of scope

ErrInvalidFieldValue (schema/field.go) is not part of this model. It represents runtime field-value validation (HTTP 400 user-input errors) rather than schema-definition validation. A separate FieldValueError type with HTTP 400 mapping may follow in a future release.

See also

Released under the MIT License.