---
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 的主要写作者是 agent，诊断需要可解析、可收集、可测试。

## 选项

- 异常。
- 全局错误码。
- `Either<Vec<Diagnostic>, World>`。

## 决定

诊断是值。`check` 返回二选一：成功带世界，失败带诊断列表。

## 理由

- 诊断可以被收集、过滤、序列化、测试。
- agent 可以直接解析 `code`、`span`、`suggestion`。
- 不依赖控制流，每个阶段显式返回诊断。

## 后果

没有全局错误状态；每个阶段自己返回诊断。渲染、排序和建议应用都是诊断值之上的操作。

Source: https://koine.systems/notes/decisions/0007-diagnostics-as-values/index.mdx
