Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug: Parsing payload fails when using a schemaTask with numbers that are transformed to bignumbers #2460

@RickVM

Description

@RickVM

Provide environment information

  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.09 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.14.2 - ~/Library/pnpm/pnpm
    bun: 1.0.35 - ~/.bun/bin/bun

Describe the bug

I would expect the number to be accepted, validation to succeed and the resulting payload object to contain a bignumber.

Instead, despite clearly giving a number, we get a zod validation error stating that a (bignumber) object was verified instead of a number.

TaskPayloadParsedError: Parsing payload with schema failed: [
  {
    "expected": "number",
    "code": "invalid_type",
    "path": [
      "foo"
    ],
    "message": "Invalid input: expected number, received object"
  }
]

Reproduction repo

https://github.com/RickVM/trigger-dev-transform-bug-repro

To reproduce

Simply run debugTask.
This is all the code:

import { logger, schemaTask } from "@trigger.dev/sdk";
import { bignumber } from "mathjs";
import { z } from "zod";

export const subTask = schemaTask({
  id: "debug-sub-task",
  schema: z.object({
    foo: z.number().transform((val) => bignumber(val)),
  }),
  run: async (_) => {
    // throws err before.
    logger.info("Sub task started");

    return {
      message: "Sub task completed",
    };
  },
});

export const mainTask = schemaTask({
  id: "debug-task",
  schema: z.object({
    someNumber: z.number().default(1),
  }),
  run: async (payload) => {
    const result = await subTask.triggerAndWait({ foo: payload.someNumber });
    logger.info("Sub task result", { result });

    return {
      message: "Main task completed",
    };
  },
});

export default mainTask;

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions