You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: migrate warnings/errors to structured diagnostics via logs-sdk (#285)
* feat: migrate warnings/errors to structured diagnostics via logs-sdk
Replace inconsistent console.warn/error/throw patterns with structured
diagnostics using @antfu/experimental-logs-sdk. Each error gets a unique
code (DTK0001-DTK0032 for core/rpc, RDDT0001-RDDT0002 for rolldown)
with auto-generated docs URLs and ANSI-formatted output.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: add throw keyword before logger.throw() for TypeScript control flow
TypeScript doesn't narrow types after `logger.CODE().throw()` because
the return type inference doesn't propagate `never` through the chained
call. Adding `throw` before the expression fixes control flow analysis.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: migrate from @antfu/experimental-logs-sdk to logs-sdk@0.0.5
Package renamed from `@antfu/experimental-logs-sdk` to `logs-sdk`
(now under vercel-labs/logs-sdk). Updated all imports, catalog entry,
and docs references.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: add structured diagnostics guide to AGENTS.md
Document the error code system (prefixes, numbering, diagnostics files)
and step-by-step instructions for adding new errors so future agents
follow the established pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: upgrade logs-sdk to 0.0.6
Rename `reporter` to `reporters` in createLogger options to match the
updated API.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+67Lines changed: 67 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,73 @@ pnpm -C docs run docs # docs dev server
62
62
- Shared UI components/preset in `packages/ui`; use `presetDevToolsUI` from `@vitejs/devtools-ui/unocss`.
63
63
- Currently focused on Rolldown build-mode analysis; dev-mode support is deferred.
64
64
65
+
## Structured Diagnostics (Error Codes)
66
+
67
+
All node-side warnings and errors use structured diagnostics via [`logs-sdk`](https://github.com/vercel-labs/logs-sdk). Never use raw `console.warn`, `console.error`, or `throw new Error` with ad-hoc messages in node-side code — always define a coded diagnostic.
Codes are sequential 4-digit numbers per prefix (e.g. `DTK0033`, `RDDT0003`). Check the existing diagnostics file to find the next available number.
78
+
79
+
### Adding a new error
80
+
81
+
1.**Define the code** in the appropriate `diagnostics.ts`:
82
+
```txt
83
+
// diagnostics.ts
84
+
DTK0033: {
85
+
message: (p: { name: string }) => `Something went wrong with "${p.name}"`,
86
+
hint: 'Optional hint for the user.',
87
+
level: 'warn', // defaults to 'error' if omitted
88
+
},
89
+
```
90
+
91
+
2.**Use the logger** at the call site:
92
+
```ts
93
+
import { logger } from'./diagnostics'
94
+
95
+
// For thrown errors — always prefix with `throw` for TypeScript control flow:
96
+
throwlogger.DTK0033({ name }).throw()
97
+
98
+
// For logged warnings/errors (not thrown):
99
+
logger.DTK0033({ name }).log() // uses definition level
100
+
logger.DTK0033({ name }).warn() // override to warn
101
+
logger.DTK0033({ name }, { cause: error }).log() // attach cause
102
+
```
103
+
104
+
3.**Create a docs page** at `docs/errors/DTK0033.md`:
105
+
```md
106
+
---
107
+
outline: deep
108
+
---
109
+
# DTK0033: Short Title
110
+
> Package: `@vitejs/devtools`
111
+
## Message
112
+
> Something went wrong with "`{name}`"
113
+
## Cause
114
+
When and why this occurs.
115
+
## Example
116
+
Code that triggers it.
117
+
## Fix
118
+
How to resolve it.
119
+
## Source
120
+
`packages/core/src/node/filename.ts`
121
+
```
122
+
123
+
4.**Update the index** at `docs/errors/index.md` — add a row to the table.
124
+
125
+
5.**Update the sidebar** in `docs/.vitepress/config.ts` — the DTK items are auto-generated from `Array.from({ length: N })`, so increment the length. RDDT items are listed manually.
This error is thrown by `RpcFunctionsCollectorBase.register()` when you attempt to register an RPC function with a name that already exists in the collector. Each function name must be unique within a collector instance unless you explicitly opt into overwriting.
> RPC function "`{name}`" is not registered. Use register() to add new functions.
12
+
13
+
## Cause
14
+
15
+
This error is thrown by `RpcFunctionsCollectorBase.update()` when you attempt to update a function definition that has not been registered yet. The `update()` method is intended for replacing an existing definition, not for adding new ones.
// Throws DTK0002 because 'my-plugin:get-version' was never registered
29
+
collector.update(getVersion)
30
+
```
31
+
32
+
## Fix
33
+
34
+
Register the function first with `register()`, then use `update()` for subsequent changes. Alternatively, pass `force: true` to `update()` to allow upserting:
This error is thrown by `RpcFunctionsCollectorBase.getSchema()` when you request the argument and return schemas for a function name that does not exist in the collector. The function must be registered before its schema can be queried.
16
+
17
+
## Example
18
+
19
+
```ts
20
+
// Throws DTK0003 because 'my-plugin:get-config' was never registered
> Either handler or setup function must be provided for RPC function "`{name}`"
12
+
13
+
## Cause
14
+
15
+
This error is thrown by `getRpcHandler()` when an RPC function definition provides neither a `handler` property nor a `setup` function that returns a `handler`. It can occur in two situations:
16
+
17
+
1. When the collector's proxy tries to resolve a handler for a registered function.
18
+
2. During `dumpFunctions()` when resolving handlers for pre-computation.
19
+
20
+
Every RPC function must have a way to produce a handler -- either directly via `handler` or lazily via `setup`.
0 commit comments