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
Copy file name to clipboardExpand all lines: AGENTS.md
+9-11Lines changed: 9 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ The kit is the integration hub. When adding to it, the question is "does this he
93
93
94
94
## Structured Diagnostics (Error Codes)
95
95
96
-
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.
96
+
All node-side warnings and errors use structured diagnostics via [`nostics`](https://github.com/vercel-labs/nostics). Never use raw `console.warn`, `console.error`, or `throw new Error` with ad-hoc messages in node-side code — always define a coded diagnostic.
97
97
98
98
### Code prefixes
99
99
@@ -115,23 +115,21 @@ Codes are sequential 4-digit numbers per prefix (e.g. `DTK0033`, `RDDT0003`). Ch
115
115
```txt
116
116
// diagnostics.ts
117
117
DTK0033: {
118
-
message: (p: { name: string }) => `Something went wrong with "${p.name}"`,
119
-
hint: 'Optional hint for the user.',
120
-
level: 'warn', // defaults to 'error' if omitted
118
+
why: (p: { name: string }) => `Something went wrong with "${p.name}"`,
119
+
fix: 'Optional remediation hint for the user.',
121
120
},
122
121
```
123
122
124
-
2.**Use the logger** at the call site:
123
+
2.**Emit the diagnostic** at the call site:
125
124
```ts
126
-
import { logger } from'./diagnostics'
125
+
import { diagnostics } from'./diagnostics'
127
126
128
127
// For thrown errors — always prefix with `throw` for TypeScript control flow:
129
-
throwlogger.DTK0033({ name }).throw()
128
+
throwdiagnostics.DTK0033.throw({ name })
130
129
131
-
// For logged warnings/errors (not thrown):
132
-
logger.DTK0033({ name }).log() // uses definition level
133
-
logger.DTK0033({ name }).warn() // override to warn
134
-
logger.DTK0033({ name }, { cause: error }).log() // attach cause
130
+
// For reported (non-thrown) diagnostics:
131
+
diagnostics.DTK0033.report({ name })
132
+
diagnostics.DTK0033.report({ name, cause: error }) // attach cause via params
135
133
```
136
134
137
135
3.**Create a docs page** at `docs/errors/DTK0033.md`:
- Each prefix maps to a package: `DTK` for `@vitejs/devtools` (Vite-specific pieces), `RDDT` for `@vitejs/devtools-rolldown`. The framework-neutral `devframe` package documents its own `DF`-prefixed codes at the [Devframe docs site](https://devfra.me/errors/).
13
13
- Every error page includes the cause, recommended fix, and a reference to the source file that emits it.
14
-
- The diagnostics system is powered by [`logs-sdk`](https://github.com/vercel-labs/logs-sdk), which provides structured logging with docs URLs, ANSI-formatted console output, and level-based filtering.
14
+
- The diagnostics system is powered by [`nostics`](https://github.com/vercel-labs/nostics), which provides structured diagnostic codes with docs URLs and ANSI-formatted console output.
Copy file name to clipboardExpand all lines: docs/kit/diagnostics.md
+31-48Lines changed: 31 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Structured Diagnostics
2
2
3
-
`ctx.diagnostics` is a thin layer over [`logs-sdk`](https://github.com/vercel-labs/logs-sdk) that lets DevTools plugins register coded errors and warnings into a shared logger without depending on `logs-sdk` directly. Use it for author-defined coded diagnostics — errors, warnings, deprecations — that carry a stable code, a documentation URL, and a structured payload. For free-form runtime output that should appear in the DevTools UI, use [`ctx.messages`](./messages).
3
+
`ctx.diagnostics` is a thin layer over [`nostics`](https://github.com/vercel-labs/nostics) that lets DevTools plugins register coded errors and warnings into a shared registry without depending on `nostics` directly. Use it for author-defined coded diagnostics — errors, warnings, deprecations — that carry a stable code, a documentation URL, and a structured payload. For free-form runtime output that should appear in the DevTools UI, use [`ctx.messages`](./messages).
4
4
5
5
| Surface | Purpose | Example |
6
6
|---------|---------|---------|
@@ -11,17 +11,20 @@
11
11
12
12
```ts
13
13
interfaceDevToolsDiagnosticsHost {
14
-
/** Combined logs-sdk Logger across all registered diagnostics. */
15
-
readonly logger:Logger
14
+
/**
15
+
* Proxy-backed lookup of every registered code by name. Each entry is a
16
+
* `nostics` handle with `.report()` and `.throw()` methods.
//Now you can emit codes through the shared logger:
57
-
ctx.diagnostics.logger.MYP0002().log()
58
+
//Emit codes through the shared lookup:
59
+
ctx.diagnostics.logger.MYP0002.report()
58
60
},
59
61
},
60
62
}
@@ -74,68 +76,49 @@ Prefixes used by the in-tree packages:
74
76
|`RDDT`|`@vitejs/devtools-rolldown`|
75
77
|`VDT`|`@vitejs/devtools-vite` (reserved) |
76
78
77
-
Each definition supports `message` (string or function), optional `hint`, optional `level` (`'error'` / `'warn'` / `'suggestion'` / `'deprecation'` — defaults to `'error'`), and a `docsBase` for generating documentation URLs.
79
+
Each definition supports `why` (string or function returning a string) and an optional `fix` (string or function). A `docsBase` on the definition group auto-attaches a per-code URL to every emitted diagnostic.
78
80
79
81
## Emit a diagnostic
80
82
81
-
Each registered code becomes a callable factory on `ctx.diagnostics.logger`. The factory returns an object with `.throw()`, `.warn()`, `.error()`, `.log()`, and `.format()`.
83
+
Each registered code is reachable as a property on `ctx.diagnostics.logger`. Every handle exposes `.throw(params)`and `.report(params)`.
`.throw()` is typed `never`. Prefix the call with `throw` so TypeScript narrows control flow correctly:
98
97
99
98
```ts
100
-
throwctx.diagnostics.logger.MYP0001({ name }).throw()
99
+
throwctx.diagnostics.logger.MYP0001.throw({ name })
101
100
```
102
101
103
-
## Typed logger reference
102
+
## Typed handle reference
104
103
105
-
`ctx.diagnostics.logger` is loosely typed — it covers an unbounded set of registered codes, beyond what TypeScript can narrow. For autocompletion on your plugin's specific codes, keep a typed reference returned from `createLogger`:
104
+
`ctx.diagnostics.logger` is a loosely typed proxy — it covers an unbounded set of registered codes, beyond what TypeScript can narrow. For autocompletion on your plugin's specific codes, keep a reference to the typed handle returned by `defineDiagnostics()`:
Both loggers share the formatter and reporter defaults set by the host (ANSI console output).
124
-
125
-
## Don't cache the combined logger
126
-
127
-
`ctx.diagnostics.logger` is a getter — it returns the freshest combined logger, rebuilt each time `register()` is called. Don't cache it across registrations:
0 commit comments