Skip to content
New issue

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

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

Already on GitHub? # to your account

Version Packages #2480

Merged
merged 1 commit into from
Apr 8, 2024
Merged

Version Packages #2480

merged 1 commit into from
Apr 8, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Apr 5, 2024

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

@effect/cli@0.35.29

Patch Changes

@effect/experimental@0.14.12

Patch Changes

@effect/platform@0.48.27

Patch Changes

@effect/platform-browser@0.31.27

Patch Changes

@effect/platform-bun@0.32.40

Patch Changes

  • Updated dependencies [c6dd3c6, 672f137, 672f137]:
    • @effect/platform@0.48.27
    • @effect/platform-node-shared@0.3.27

@effect/platform-node@0.45.29

Patch Changes

  • Updated dependencies [c6dd3c6, 672f137, 672f137]:
    • @effect/platform@0.48.27
    • @effect/platform-node-shared@0.3.27

@effect/platform-node-shared@0.3.27

Patch Changes

@effect/rpc@0.29.3

Patch Changes

@effect/rpc-http@0.27.3

Patch Changes

@effect/schema@0.64.20

Patch Changes

  • #2483 42b3651 Thanks @gcanti! - Add ParseIssueTitle annotation, closes From Discord: Enhancing Debugging with Custom Error Messages in Schema Validation #2482

    When a decoding or encoding operation fails, it's useful to have additional details in the default error message returned by TreeFormatter to understand exactly which value caused the operation to fail. To achieve this, you can set an annotation that depends on the value undergoing the operation and can return an excerpt of it, making it easier to identify the problematic value. A common scenario is when the entity being validated has an id field. The ParseIssueTitle annotation facilitates this kind of analysis during error handling.

    The type of the annotation is:

    export type ParseIssueTitleAnnotation = (
      issue: ParseIssue,
    ) => string | undefined;

    If you set this annotation on a schema and the provided function returns a string, then that string is used as the title by TreeFormatter, unless a message annotation (which has the highest priority) has also been set. If the function returns undefined, then the default title used by TreeFormatter is determined with the following priorities:

    • identifier
    • title
    • description
    • ast.toString()

    Example

    import type { ParseIssue } from "@effect/schema/ParseResult";
    import * as S from "@effect/schema/Schema";
    
    const getOrderItemId = ({ actual }: ParseIssue) => {
      if (S.is(S.struct({ id: S.string }))(actual)) {
        return `OrderItem with id: ${actual.id}`;
      }
    };
    
    const OrderItem = S.struct({
      id: S.string,
      name: S.string,
      price: S.number,
    }).annotations({
      identifier: "OrderItem",
      parseIssueTitle: getOrderItemId,
    });
    
    const getOrderId = ({ actual }: ParseIssue) => {
      if (S.is(S.struct({ id: S.number }))(actual)) {
        return `Order with id: ${actual.id}`;
      }
    };
    
    const Order = S.struct({
      id: S.number,
      name: S.string,
      items: S.array(OrderItem),
    }).annotations({
      identifier: "Order",
      parseIssueTitle: getOrderId,
    });
    
    const decode = S.decodeUnknownSync(Order, { errors: "all" });
    
    // No id available, so the `identifier` annotation is used as the title
    decode({});
    /*
    throws
    Error: Order
    ├─ ["id"]
    │  └─ is missing
    ├─ ["name"]
    │  └─ is missing
    └─ ["items"]
       └─ is missing
    */
    
    // An id is available, so the `parseIssueTitle` annotation is used as the title
    decode({ id: 1 });
    /*
    throws
    Error: Order with id: 1
    ├─ ["name"]
    │  └─ is missing
    └─ ["items"]
       └─ is missing
    */
    
    decode({ id: 1, items: [{ id: "22b", price: "100" }] });
    /*
    throws
    Error: Order with id: 1
    ├─ ["name"]
    │  └─ is missing
    └─ ["items"]
       └─ ReadonlyArray<OrderItem>
          └─ [0]
             └─ OrderItem with id: 22b
                ├─ ["name"]
                │  └─ is missing
                └─ ["price"]
                   └─ Expected a number, actual "100"
    */

    In the examples above, we can see how the parseIssueTitle annotation helps provide meaningful error messages when decoding fails.

@github-actions github-actions bot force-pushed the changeset-release/main branch 2 times, most recently from 17ef04e to 7adae93 Compare April 5, 2024 14:16
@github-actions github-actions bot requested a review from gcanti as a code owner April 5, 2024 14:16
@github-actions github-actions bot force-pushed the changeset-release/main branch from 7adae93 to b9a5671 Compare April 7, 2024 23:52
@github-actions github-actions bot force-pushed the changeset-release/main branch from b9a5671 to b3d339c Compare April 8, 2024 00:02
@tim-smart tim-smart merged commit 43c5d93 into main Apr 8, 2024
@tim-smart tim-smart deleted the changeset-release/main branch April 8, 2024 01:08
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

From Discord: Enhancing Debugging with Custom Error Messages in Schema Validation
1 participant