Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseResult.ArrayFormatter: correct _tag fields for Refinement an… #4565

Merged
merged 1 commit into from
Mar 9, 2025

Conversation

gcanti
Copy link
Contributor

@gcanti gcanti commented Mar 9, 2025

…d Transformation issues, closes #4564

This update fixes an issue where ParseResult.ArrayFormatter incorrectly labeled Refinement and Transformation errors as Type in the output.

Before

import { Effect, ParseResult, Schema } from "effect"

const schema = Schema.Struct({
  a: Schema.NonEmptyString,
  b: Schema.NumberFromString
})

const input = { a: "", b: "" }

const program = Schema.decodeUnknown(schema, { errors: "all" })(input).pipe(
  Effect.catchTag("ParseError", (err) =>
    ParseResult.ArrayFormatter.formatError(err).pipe(
      Effect.map((err) => JSON.stringify(err, null, 2))
    )
  )
)

program.pipe(Effect.runPromise).then(console.log)
/*
[
  {
    "_tag": "Type", ❌
    "path": [
      "a"
    ],
    "message": "Expected a non empty string, actual \"\""
  },
  {
    "_tag": "Type", ❌
    "path": [
      "b"
    ],
    "message": "Unable to decode \"\" into a number"
  }
]
*/

After

import { Effect, ParseResult, Schema } from "effect"

const schema = Schema.Struct({
  a: Schema.NonEmptyString,
  b: Schema.NumberFromString
})

const input = { a: "", b: "" }

const program = Schema.decodeUnknown(schema, { errors: "all" })(input).pipe(
  Effect.catchTag("ParseError", (err) =>
    ParseResult.ArrayFormatter.formatError(err).pipe(
      Effect.map((err) => JSON.stringify(err, null, 2))
    )
  )
)

program.pipe(Effect.runPromise).then(console.log)
/*
[
  {
    "_tag": "Refinement", ✅
    "path": [
      "a"
    ],
    "message": "Expected a non empty string, actual \"\""
  },
  {
    "_tag": "Transformation", ✅
    "path": [
      "b"
    ],
    "message": "Unable to decode \"\" into a number"
  }
]
*/

@gcanti gcanti added the schema label Mar 9, 2025
Copy link

changeset-bot bot commented Mar 9, 2025

🦋 Changeset detected

Latest commit: 6861398

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

This PR includes changesets to release 36 packages
Name Type
effect Patch
@effect/cli Patch
@effect/cluster-browser Patch
@effect/cluster-node Patch
@effect/cluster-workflow Patch
@effect/cluster Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/platform Patch
@effect/printer-ansi Patch
@effect/printer Patch
@effect/rpc-http Patch
@effect/rpc Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-drizzle Patch
@effect/sql-kysely Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql Patch
@effect/typeclass Patch
@effect/vitest Patch
@effect/ai Patch
@effect/ai-anthropic Patch
@effect/ai-openai 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

@gcanti gcanti merged commit 22d2ebb into main Mar 9, 2025
11 checks passed
@gcanti gcanti deleted the fix-4564 branch March 9, 2025 07:52
@github-actions github-actions bot mentioned this pull request Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

From Discord: Improving Schema Error Reporting to Match VineJS
1 participant