Skip to content

(v1) Unify error normalization and formatting#1157

Open
yamcodes wants to merge 7 commits into
v1from
709-unify-error-normalization-and-formatting
Open

(v1) Unify error normalization and formatting#1157
yamcodes wants to merge 7 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: c0a5415

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

This PR includes changesets to release 4 packages
Name Type
arkenv Minor
@arkenv/bun-plugin Patch
@arkenv/nextjs 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 5 2026, 10:45 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/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/vite-plugin

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

commit: c0a5415

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify error normalization and formatting

1 participant