Skip to content

More rich error messages #7

@kakasoo

Description

@kakasoo

Background

The following are the errors that I am currently using this library.

{
  "type": "failure",
  "diagnostics": [
    {
      "file": "src/providers/patch__communityPlatform_posts_$postId_comments.ts",
      "category": "error",
      "code": 2322,
      "start": 2791,
      "length": 8,
      "messageText": "Type '{ id: string; display_name: string | null; created_at: Date; updated_at: Date; deleted_at: Date | null; body: string; community_platform_user_id: string; community_platform_post_id: string; parent_id: string | null; }[]' is not assignable to type 'ICommunityPlatformComment[]'."
    },
    {
      "file": "src/providers/patch__communityPlatform_posts_$postId_comments.ts",
      "category": "error",
      "code": 2322,
      "start": 2906,
      "length": 5,
      "messageText": "Type '{ body?: { contains: string; mode: string; } | undefined; community_platform_user_id?: (string & typia.tags.Format<\"uuid\">) | undefined; display_name?: { contains: string; mode: string; } | undefined; parent_id?: (string & typia.tags.Format<\"uuid\">) | undefined; community_platform_post_id: string & typia.tags.Format<\"uuid\">; deleted_at: null; }' is not assignable to type 'community_platform_commentsWhereInput'."
    }
  ]
}

However, because vscode provides more detailed error logs, it was doubtful that this library was not able to export some of the messages.
Through monkey patches, I modified the code from the library called autobe as follows.
Please check the code below.

Before

function getMessageText(text: string | ts.DiagnosticMessageChain): string {
  return typeof text === "string" ? text : text.messageText;
}

To Be

function getMessageText(text: string | ts.DiagnosticMessageChain): string {
  return typeof text === "string"
    ? text
    : ts.flattenDiagnosticMessageText(text, "\n");
}

Enhanced error message

{
  "type": "failure",
  "diagnostics": [
    {
      "file": "src/providers/patch__communityPlatform_posts_$postId_comments.ts",
      "category": "error",
      "code": 2322,
      "start": 2791,
      "length": 8,
      "messageText": "Type '{ id: string; display_name: string | null; created_at: Date; updated_at: Date; deleted_at: Date | null; body: string; community_platform_user_id: string; community_platform_post_id: string; parent_id: string | null; }[]' is not assignable to type 'ICommunityPlatformComment[]'.\n  Type '{ id: string; display_name: string | null; created_at: Date; updated_at: Date; deleted_at: Date | null; body: string; community_platform_user_id: string; community_platform_post_id: string; parent_id: string | null; }' is not assignable to type 'ICommunityPlatformComment'.\n    Types of property 'created_at' are incompatible.\n      Type 'Date' is not assignable to type 'string & Format<\"date-time\">'.\n        Type 'Date' is not assignable to type 'string'."
    },
    {
      "file": "src/providers/patch__communityPlatform_user_postVotes.ts",
      "category": "error",
      "code": 2322,
      "start": 3158,
      "length": 5,
      "messageText": "Type 'number | (number & Type<\"int32\">)' is not assignable to type 'number & Type<\"int32\"> & Minimum<1>'.\n  Type 'number & Type<\"int32\">' is not assignable to type 'number & Type<\"int32\"> & Minimum<1>'.\n    Type 'number & Type<\"int32\">' is not assignable to type 'Minimum<1>'.\n      Types of property '\"typia.tag\"' are incompatible.\n        Type '{ target: \"number\"; kind: \"type\"; value: \"int32\"; validate: \"$importInternal(\\\"isTypeInt32\\\")($input)\"; exclusive: true; schema: { type: \"integer\"; }; } | undefined' is not assignable to type '{ target: \"number\"; kind: \"minimum\"; value: 1; validate: \"1 <= $input\"; exclusive: [\"minimum\", \"exclusiveMinimum\"]; schema: { minimum: 1; }; } | undefined'.\n          Type '{ target: \"number\"; kind: \"type\"; value: \"int32\"; validate: \"$importInternal(\\\"isTypeInt32\\\")($input)\"; exclusive: true; schema: { type: \"integer\"; }; }' is not assignable to type '{ target: \"number\"; kind: \"minimum\"; value: 1; validate: \"1 <= $input\"; exclusive: [\"minimum\", \"exclusiveMinimum\"]; schema: { minimum: 1; }; }'.\n            Types of property 'kind' are incompatible.\n              Type '\"type\"' is not assignable to type '\"minimum\"'."
    }
  ]
}
Image

The error message is enriched, which is exactly the same as the error provided by vscode. The key is to recursively navigate the 'ts.DiagnosticMessageChain' object and solve the entire message.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions