---
title: "错误码"
---

> Documentation Index
> Fetch the complete documentation index at: https://koine.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# 错误码

Koine 的诊断码是分段文本：

```text
koine.<phase>.<kind>
```

- `phase` 是产生错误的阶段；阶段定义见[诊断](https://koine.systems/reference/spec/diagnostics/#阶段)。
- `kind` 是稳定的语义类别，不带动态信息。
- 码一旦发布就稳定，不复用。

## 当前码表

| 码 | 含义 |
| --- | --- |
| `koine.parse.unexpected-token` | 意外的 token |
| `koine.parse.unclosed-delimiter` | 未闭合的括号 |
| `koine.parse.chained-comparison` | 比较运算符被链式使用，例如 `a < b < c` |
| `koine.resolve.unknown-sort` | 未知类型 |
| `koine.resolve.unknown-relation` | 未知关系 |
| `koine.resolve.unknown-define` | 未知 define |
| `koine.type.not-relation` | transition 目标不是关系 |
| `koine.run.unknown-state` | 场景起点不是已知 state |
| `koine.resolve.unknown-entity` | 未知实体 |
| `koine.resolve.duplicate-name` | 重名 |
| `koine.resolve.define-cycle` | define 直接/间接/互递归，或与 derived relation 交叉递归 |
| `koine.resolve.alias-cycle` | alias 依赖成环 |
| `koine.resolve.alias-target-not-type` | alias 目标不是类型 |
| `koine.type.duplicate-field` | 产品值字段重复 |
| `koine.type.unknown-field` | 访问了产品值不存在的字段 |
| `koine.type.missing-field` | 产品值构造缺少字段 |
| `koine.quantity.cycle` | quantity 量纲依赖成环 |
| `koine.unit.unknown-quantity` | unit 指向未知 quantity |
| `koine.unit.invalid-factor` | unit factor 不是正数 |
| `koine.unit.unknown-unit` | unit expression 引用了未知 unit |
| `koine.unit.cycle` | unit 依赖成环 |
| `koine.unit.invalid-expression` | unit expression 无法解析 |
| `koine.type.dimension-mismatch` | 量纲不匹配 |
| `koine.key.full-key-modifier` | `key total` / `key partial` 用在全部参数上 |
| `koine.naming.key-not-prefix` | 显式 key 参数不是 relation 参数列表的前缀（warning） |
| `koine.doc.missing-gloss` | relation 缺少 `@gloss` |
| `koine.doc.unknown-placeholder` | `@gloss` 使用了未知参数占位符 |
| `koine.doc.duplicate-gloss` | `@gloss` 出现多次 |
| `koine.doc.duplicate-example` | 重复的 `@example` |
| `koine.doc.unattached` | 文档注释未附着到声明 |
| `koine.doc.example-arity` | `@example` 的关系名或参数数量不匹配 |
| `koine.doc.empty-example` | `@example` 没有自然语言、也没有关系实例 |
| `koine.doc.example-no-context` | `@example` 只有关系实例、没有自然语言（迁移期 warning） |
| `koine.doc.unknown-tag` | 文档注释里出现未知 tag |
| `koine.doc.missing-placeholder` | `@gloss` 缺少参数占位符 |
| `koine.doc.empty-gloss` | `@gloss` 只有占位符 |
| `koine.derive.unknown-relation` | 派生关系引用了未知关系 |
| `koine.derive.cycle` | 派生关系依赖成环 |
| `koine.derive.not-writable` | transition 试图写派生关系 |
| `koine.derive.type-mismatch` | 派生关系类型不匹配 |
| `koine.derive.key-violation` | 派生关系的 key 声明无效，或公式违反 key / total 覆盖 |
| `koine.type.arity-mismatch` | 参数数量不匹配 |
| `koine.type.sort-mismatch` | 参数类型不匹配 |
| `koine.type.define-return-not-value` | define 返回 relation / view / transition |
| `koine.type.define-context` | define 出现在禁止的上下文 |
| `koine.type.expected-bool` | require / axiom / 过滤条件不是 Bool |
| `koine.type.functional-read-partial` | 对 `key partial` 关系做函数式读取 |
| `koine.type.quantifier-domain` | 量词绑定了不允许的类型 |
| `koine.type.operator-mismatch` | 运算符两边类型不匹配 |
| `koine.type.mixed-numeric` | Int 与 Decimal 混用，需要显式转换 |
| `koine.type.operator-not-defined` | 该类型没有这个运算符，例如 Text `<` |
| `koine.type.aggregate-element` | 聚合元素类型不支持 |
| `koine.type.aggregate-empty` | 空集 `min`/`max` |
| `koine.type.aggregate-binder` | 聚合 binder 不是 entity 类型 |
| `koine.type.aggregate-filter` | 聚合过滤不是 Bool |
| `koine.type.aggregate-shadow` | 聚合 binder 重名/遮蔽外层名字 |
| `koine.state.duplicate-entity` | 实体重复声明 |
| `koine.state.duplicate-tuple` | 元组重复 |
| `koine.state.invalid-item` | 非法的世界项 |
| `koine.state.missing-total-key` | state 缺少 total key 行 |
| `koine.state.missing-time` | world body 缺少 `time` |
| `koine.state.duplicate-key` | 真子集 key 在同一个世界里出现多行 |
| `koine.state.key-invalid` | state relation 的 key 声明无效（参数不是关系参数子集或重复） |
| `koine.axiom.violated` | 世界违反 axiom（init/state/transition/find/explore 候选） |
| `koine.eval.division-by-zero` | 除数为 0 |
| `koine.eval.non-terminating-division` | 除法结果不是有限十进制，需要显式 `divide` |
| `koine.eval.decimal-limit` | 超出实现的 Decimal 位数或 scale 限制 |
| `koine.run.unknown-transition` | 场景里的 transition 不存在 |
| `koine.run.binding-mismatch` | 绑定与参数不匹配 |
| `koine.run.step-rejected` | 某一步不合法 |

## 结构

诊断值的字段、建议编辑和应用规则见[诊断结构](https://koine.systems/reference/spec/diagnostics/#结构)。本页不重复定义。

## 相关

- [语言规范](https://koine.systems/reference/spec/)
- [诊断](https://koine.systems/reference/spec/diagnostics/)
- [特性表](https://koine.systems/reference/features/)

Source: https://koine.systems/reference/errors/index.mdx
