Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ import { useSafeRuntimeConfig } from '#imports'
| `$schema` | `StandardSchemaV1` | — | Your validation schema (required) |
| `validateAtBuild` | `boolean` | `true` | Validate during dev/build |
| `validateAtRuntime` | `boolean` | `false` | Validate when server starts |
| `onBuildError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | How to handle build validation errors |
| `onRuntimeError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | How to handle runtime validation errors |
| `logSuccess` | `boolean` | `true` | Log successful validation |
| `logFallback` | `boolean` | `true` | Log when using JSON Schema fallback |
| `onError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | How to handle validation errors |
| `jsonSchemaTarget` | `string` | `'draft-2020-12'` | JSON Schema version for runtime validation |
| `shelve` | `boolean \| ShelveOptions` | `undefined` | Shelve secrets integration (see below) |

Expand Down Expand Up @@ -278,6 +275,7 @@ export default defineNuxtConfig({
safeRuntimeConfig: {
$schema: runtimeConfigSchema,
validateAtRuntime: true,
onError: 'throw',
},
})
```
Expand Down
12 changes: 2 additions & 10 deletions docs/content/1.guide/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ All options for `safeRuntimeConfig` in your `nuxt.config.ts`.
| `$schema` | `StandardSchemaV1` | - | Your validation schema (required) |
| `validateAtBuild` | `boolean` | `true` | Validate during dev/build |
| `validateAtRuntime` | `boolean` | `false` | Validate when server starts |
| `onBuildError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | Build validation error behavior |
| `onRuntimeError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | Runtime validation error behavior |
| `logSuccess` | `boolean` | `true` | Log successful validation |
| `logFallback` | `boolean` | `true` | Log JSON Schema fallback warnings |
| `onError` | `'throw' \| 'warn' \| 'ignore'` | `'throw'` | Validation error behavior |
| `jsonSchemaTarget` | `string` | `'draft-2020-12'` | JSON Schema version for runtime |

## Example Configuration
Expand All @@ -30,12 +27,7 @@ export default defineNuxtConfig({
validateAtRuntime: false, // opt-in

// Error handling
onBuildError: 'throw', // stop build on error
onRuntimeError: 'warn', // log warning, don't crash

// Logging
logSuccess: true,
logFallback: true,
onError: 'throw', // 'throw' | 'warn' | 'ignore'

// JSON Schema
jsonSchemaTarget: 'draft-2020-12',
Expand Down
7 changes: 4 additions & 3 deletions docs/content/1.guide/4.validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineNuxtConfig({
safeRuntimeConfig: {
$schema: runtimeConfigSchema,
validateAtRuntime: true,
onError: 'throw',
},
})
```
Expand All @@ -61,14 +62,13 @@ What it catches:

## Error Handling

Control how validation errors are handled:
Use `onError` to control how both build-time and runtime validation errors are handled:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
safeRuntimeConfig: {
$schema: runtimeConfigSchema,
onBuildError: 'throw', // 'throw' | 'warn' | 'ignore'
onRuntimeError: 'throw', // 'throw' | 'warn' | 'ignore'
onError: 'throw', // 'throw' | 'warn' | 'ignore'
},
})
```
Expand Down Expand Up @@ -98,6 +98,7 @@ export default defineNuxtConfig({
$schema: runtimeConfigSchema,
validateAtBuild: true, // catch dev errors
validateAtRuntime: true, // catch prod errors
onError: 'throw',
},
})
```
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"test": "vitest run",
"test:watch": "vitest watch",
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
"test:packed-release": "node scripts/smoke-packed-release.mjs",
"test:nuxt5-nightly": "node scripts/smoke-nuxt5-nightly.mjs"
},
"peerDependencies": {
Expand All @@ -64,6 +65,7 @@
"@cfworker/json-schema": "catalog:",
"@standard-community/standard-json": "catalog:",
"@standard-schema/spec": "catalog:",
"@typescript-eslint/utils": "catalog:",
"@valibot/to-json-schema": "catalog:",
"consola": "catalog:",
"defu": "catalog:",
Expand All @@ -84,7 +86,7 @@
"@types/node": "catalog:",
"@typescript-eslint/parser": "catalog:",
"@typescript-eslint/rule-tester": "catalog:",
"@typescript-eslint/utils": "catalog:",
"arktype": "catalog:",
"bumpp": "catalog:",
"changelogen": "catalog:",
"eslint": "catalog:",
Expand Down
Loading
Loading