Skip to content

(v1) Unify error normalization and formatting - #1157

Merged
yamcodes merged 48 commits into
v1from
709-unify-error-normalization-and-formatting
Jun 21, 2026
Merged

yamcodes merged 48 commits into
v1from
709-unify-error-normalization-and-formatting

Conversation

@yamcodes

@yamcodes yamcodes commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Fixes #709

Refactor the error system to use a normalized EnvIssue format, support sensitive credential masking/redaction with programmatic overrides, add a non-throwing safeCreateEnv API for RSC/Next.js integrations, and provide a stable base for CLI/IDE integrations.

@yamcodes yamcodes added enhancement New feature or improvement refactor A change to the codebase that's neither a bug fix nor added functionality labels Jun 3, 2026
@yamcodes yamcodes linked an issue Jun 3, 2026 that may be closed by this pull request
@pullfrog

pullfrog Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using Kimi K2𝕏

@changeset-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: df221c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
arkenv Major
@arkenv/bun-plugin Patch
@arkenv/nextjs Patch
@arkenv/nuxt Patch
@arkenv/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added docs Adds or changes documentation, or acts as documentation in and of itself arkenv Changes to the `arkenv` npm package. tests This issue or PR is about adding, removing or changing tests playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) labels Jun 3, 2026
@arkenv-bot

arkenv-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (Asia/Almaty)
arkenv Ready Ready Preview, Comment Jun 21 2026, 11:51 PM (Asia/Almaty)

@github-actions github-actions Bot removed the playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) label Jun 4, 2026
@pullfrog

pullfrog Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using Kimi K2𝕏

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

arkenv

npm i https://pkg.pr.new/arkenv@1157

@arkenv/build

npm i https://pkg.pr.new/@arkenv/build@1157

@arkenv/bun-plugin

npm i https://pkg.pr.new/@arkenv/bun-plugin@1157

@arkenv/cli

npm i https://pkg.pr.new/@arkenv/cli@1157

@arkenv/fumadocs-ui

npm i https://pkg.pr.new/@arkenv/fumadocs-ui@1157

@arkenv/nextjs

npm i https://pkg.pr.new/@arkenv/nextjs@1157

@arkenv/nuxt

npm i https://pkg.pr.new/@arkenv/nuxt@1157

@arkenv/vite-plugin

npm i https://pkg.pr.new/@arkenv/vite-plugin@1157

commit: c9532d0

@arkenv-bot

arkenv-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Size Report

Package Size Limit Diff Status
arkenv 2.17 kB 2.25 kB +25.4%
arkenv/standard 2.01 kB 2.05 kB +99.0%
arkenv/core 497 B 500 B +12.7%

All size limits passed!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — First review of this PR. Introduces EnvIssue type normalization across both ArkType and Standard Schema engines, safeCreateEnv non-throwing API, and sensitive-value redaction in error messages.

  • Introduce EnvIssue type with code, expected, received, meta fields replacing the flat ValidationIssue type in core.ts; deprecate old type as alias.
  • Add safeCreateEnv to both arkenv and arkenv/standard returning a SafeCreateEnvResult<T> discriminated union instead of throwing.
  • Implement secret redaction via SENSITIVE_KEYWORDS regex patterns, shouldRedact(), safeStringify(), and debugSecrets config/ARKENV_DEBUG_SECRETS env var.
  • Normalize Standard Schema errors in parse-standard.ts to resolve received values (JSON-parse + traversal), map engine-level codes to EnvIssueCode, and append styled (was …) values.
  • Map ArkType error codes to EnvIssueCode in arkErrorsToIssues with proper expected/received extraction and redaction support.
  • Update ArkEnvError to store issues publicly and accept debugSecrets options.
  • Add formatIssues/formatError utilities with deprecated formatInternalErrors alias.
  • Add changeset marking a minor version bump with breaking-change notice for error message format.
  • Add/update tests in errors.test.ts and standard-mode.test.ts for redaction, safeCreateEnv, and error normalization.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread packages/arkenv/src/core.ts Outdated
Comment thread packages/arkenv/src/core.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — incremental delta since the prior Pullfrog review. The 94f275f commit addresses both review threads: tightened sensitive-keyword regex patterns, added a public exclusion in shouldRedact, and removed the unused _options/options parameters across formatting functions and the ArkEnvError constructor.

  • Tightened SENSITIVE_KEYWORDS regex patterns — broad patterns like /key/i, /pass/i, /auth/i are now anchored to (_|^)...(_|$) boundaries to avoid false positives on non-sensitive variable names (COMPASS, AUTHOR, etc.).
  • Added public exclusion in shouldRedact — paths containing public (e.g. PUBLIC_KEY) are no longer redacted, even when they match a sensitive keyword pattern.
  • Removed unused _options parameter from formatIssues, formatError, and the deprecated formatInternalErrors — the parameter was never wired through since redaction happens at issue-creation time.
  • Removed unused options parameter from the ArkEnvError constructor, along with a duplicate formatIssues call in the constructor body.
  • Cleaned up parse-standard.ts error construction — the config passthrough to ArkEnvError (which was ignored) has been removed.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes — incremental delta since the prior Pullfrog review. The 083837c commit extracts redaction utilities into a shared module and optimizes the Standard Schema error mapping to resolve size-limit failures.

  • Extracted safeStringify / shouldRedact / SENSITIVE_PATTERN to src/utils/redact.ts — moved out of core.ts and arktype/index.ts into a shared utility module; consolidated 11 separate regex patterns into a single combined pattern.
  • Optimized parse-standard.ts error mapping — extracted getProp helper for path traversal, deduplicated type-checks via msg variable, consolidated meta extraction with ?? nullish coalescing, and streamlined message-suffix construction.
  • Bumped size-limit thresholds in package.json to 2.3 kB (arkenv) and 2.1 kB (arkenv/standard).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@yamcodes
yamcodes changed the base branch from dev to v1 June 5, 2026 15:58
@yamcodes yamcodes changed the title fix: Unify error normalization and formatting (v1) Unify error normalization and formatting Jun 6, 2026
yamcodes added 2 commits June 19, 2026 14:55
# Conflicts:
#	packages/arkenv/package.json
#	packages/arkenv/src/arkenv.ts
#	packages/arkenv/src/arktype/index.ts
#	packages/arkenv/src/index.ts
#	packages/arkenv/src/parse-standard.ts
#	packages/arkenv/src/standard-mode.test.ts
#	packages/arkenv/src/standard.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — minor suggestions inline.

Reviewed changes — incremental delta since the prior Pullfrog review at 083837c. Renames create-env.tsarkenv.ts and createEnv()arkenv(), reorganizes imports from @/ aliases to relative paths, adds coerce/arrayFormat/emptyAsUndefined/debugSecrets config options to ParseStandardConfig, adds safeCreateEnv to the arkenv/standard entry point, exposes getSchemaKeys from the main index, and bumps size-limit thresholds.

  • Renamed create-env.ts to arkenv.ts — file moved, function createEnv renamed to arkenv, safeCreateEnv moved alongside. Updated all internal callers, re-exports, and type references.
  • Reorganized arktype/index.ts imports — replaced @/arkenv, @/coercion, @/core, @/utils/style-text alias imports with relative .ts paths. Removed .ts extensions from two imports in core.ts.
  • Added coercion and redaction config to ParseStandardConfig — new coerce, arrayFormat, emptyAsUndefined, and debugSecrets options flow through the Standard Schema path alongside the existing ArkType path.
  • Wired emptyAsUndefined coercion pipeline in parse-standard.tsstripEmptyStrings applied to env before validation; extracted processedEnv variable used consistently in received-value traversal.
  • Added safeCreateEnv to arkenv/standard entry — mirrors the non-throwing API from the main arkenv export.
  • Exposed getSchemaKeys from the main index — new public utility for extracting keys from schema definitions in either ArkType or Standard Schema format.

ℹ️ Dead formatIssuePath function

formatIssuePath at packages/arkenv/src/parse-standard.ts:150 is defined but never called. The inline getProp helper + path construction replaced the call site at line 252, but the function wasn't removed. Since both implementations produce the same result, one is dead code.

Technical details
# Dead `formatIssuePath` function

## Affected sites
- `packages/arkenv/src/parse-standard.ts:150``formatIssuePath` function definition, no callers via grep

## Required outcome
- Remove the unused `formatIssuePath` function or replace the inline `getProp` + `${key}.${issue.path.map(getProp).join(".")}` pattern with a call to it.

ℹ️ Nitpicks

  • packages/arkenv/src/arkenv.ts:39 — JSDoc still references createEnv (stale from the rename to arkenv).

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread packages/arkenv/src/arktype/index.ts Outdated
Comment thread .changeset/unified-error-normalization.md Outdated
Comment thread packages/arkenv/src/arktype/index.ts Outdated
Comment thread packages/arkenv/src/arktype/index.ts Outdated
Comment thread packages/arkenv/src/arktype/index.ts Outdated
Comment thread packages/arkenv/src/core.ts Outdated
Comment thread packages/arkenv/src/core.ts Outdated
Comment thread packages/arkenv/src/core.ts Outdated
Comment thread packages/arkenv/src/core.ts Outdated
Comment thread packages/arkenv/src/parse-standard.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — delta since the prior Pullfrog review at 979c137. Replaces the standalone safeArkEnv function with a { safe: true } option on arkenv(), and changes SafeArkEnvResult from exposing the full error object to returning issues directly.

  • Replaced safeArkEnv with { safe: true } option — added overload signatures distinguishing the safe (SafeArkEnvResult<T>) and throwing (T) return types in both arkenv.ts (6 overloads) and standard.ts (2 overloads). All call sites, tests, and documentation updated to arkenv(def, { safe: true }).
  • Changed SafeArkEnvResult failure branch from { success: false; error: ArkEnvError } to { success: false; issues: readonly EnvIssue[] }. executeSafe now extracts error.issues directly.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@github-actions github-actions Bot added @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv @arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv labels Jun 21, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — 10 new commits since the prior Pullfrog review at f922185. Strips engine-specific metadata from EnvIssueMeta, removes the deprecated formatError() wrapper, expands error code maps with type-safe exhaustiveness, and hardens framework integrations against the safe: true option.

  • Removed engine metadata from EnvIssueMeta — fields engine and engineCode stripped from the type, all call sites, and all test assertions. Justified by the new ADR 0010 on bundle isolation.
  • Removed formatError() — the deprecated wrapper over formatIssues() is gone; all callers and tests updated. Changeset note updated accordingly.
  • Expanded ARKTYPE_CODE_MAP — new codes minLength, unit, proto, domain, exactLength, before, after, predicate mapped; type-safe via satisfies Record<ArkError["code"], EnvIssueCode> with in operator guard in mapArkTypeCode.
  • STANDARD_CODE_MAP now uses satisfies Record<string, EnvIssueCode> and in operator lookup, matching the ArkType pattern.
  • Made buildEnvIssue's meta parameter optional — defaults to {}, consistent with the now-optional meta field on EnvIssue.
  • Hardened framework integrations — all plugin configs (vite, bun, nextjs, nuxt) now type-restrict safe via Omit<ArkEnvConfig, "safe"> and explicitly pass safe: false at runtime.
  • Added ADR 0010 — bundle isolation over DRYness, documenting why the two parsing engines remain split despite visual similarity.
  • Added safe option docsoptions.mdx documents the safe option with an integration caveat; quickstart.mdx updated with pattern.
  • Updated changeset and skills — changeset text tightened (safeArkEnv API → { safe: true } API), formatError reference removed; changeset/SKILL.md added v1+ bump rules table.
  • Vite test mocks — added as any on mockReturnValue calls to satisfy the richer return-type union.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@yamcodes
yamcodes merged commit ea0dbd6 into v1 Jun 21, 2026
2 checks passed
@yamcodes
yamcodes deleted the 709-unify-error-normalization-and-formatting branch June 21, 2026 18:47
@arkenv-bot arkenv-bot Bot mentioned this pull request Jun 21, 2026
@yamcodes yamcodes mentioned this pull request Jun 27, 2026
13 tasks
yamcodes added a commit that referenced this pull request Jul 11, 2026
…ze warning/error prefixes (#1294)

## Summary

Introduces a dedicated `log.ts` utility module in `@arkenv/build` and
migrates all manually-prefixed log strings in the build-time and
framework integration packages to use it.

## Changes

### `@arkenv/build`
- **New:** `packages/build/src/log.ts` — defines `BUILD_PREFIX`,
`WATCHER_PREFIX`, `formatBuildError`, `logBuildWarning`,
`logBuildError`, `logWatcherError`
- Re-exports `./log` from `index.ts`
- Replaces raw string literal in `resolveLayout` and all `console.error`
calls in `watchSchema`/`closeWatcher`

### `@arkenv/nextjs`
- `config.ts`: uses `logBuildWarning`, `logBuildError`,
`formatBuildError` for deprecation warning, schema path error, codegen
error, and validation failure header
- `arkenv-internal.ts`: uses `logBuildWarning` for legacy nested-layout
deprecation

### `@arkenv/nuxt`
- `module.ts`: uses `formatBuildError` for the client-side server-only
import error

## Motivation

Follows up on #1157 — while that PR fixed casing inconsistencies, the
prefix strings were still scattered as manual literals across 5+ call
sites. This extracts them into a single, zero-dependency helper module
inside `@arkenv/build` (already a shared dep) so all integrations stay
consistent automatically.

## Verification

- 73 test files, **743 tests** — all passing ✅

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/bun-plugin Issues or Pull Requests involving the Bun plugin for ArkEnv @arkenv/cli Issues or Pull Requests involving the ArkEnv CLI @arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv arkenv Changes to the `arkenv` npm package. docs Adds or changes documentation, or acts as documentation in and of itself enhancement New feature or improvement refactor A change to the codebase that's neither a bug fix nor added functionality tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify error normalization and formatting

1 participant