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

[Bug]: Strange behavior of workflow not executing instructions #10003

Closed
Bradzer opened this issue Nov 9, 2024 · 1 comment
Closed

[Bug]: Strange behavior of workflow not executing instructions #10003

Bradzer opened this issue Nov 9, 2024 · 1 comment

Comments

@Bradzer
Copy link

Bradzer commented Nov 9, 2024

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prettier": "^3.3.3",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

20.14.0

Database and its version

16.3

Operating system name and version

Linux Mint 21.2 Cinnamon

Browser name

No response

What happended?

We have noticed a strange behavior with the workflow not executing some instructions.

For instance an error is never raised in the following code:

  const getNullValueStep = createStep(
    { name: "getNullValueStep" },
    () => {
      return new StepResponse(null);
    }
  );

  export const faultyWorkflow = createWorkflow(
    {name: "faultyWorkflow"},
    () => {
      const myNullValue = getNullValueStep();

      transform(
        {myNullValue},
        ({myNullValue}) => {
          if (!myNullValue) {
            throw new MedusaError(
              MedusaErrorTypes.NOT_ALLOWED,
              "Null value caught!"
            );
          }
        }
      );

      transform(
        {},
        (someObject) => {
          const myNullValue = null;
      
          if (!myNullValue) {
            throw new MedusaError(
              MedusaErrorTypes.NOT_ALLOWED,
              "Null value caught!"
            );
          }
        }
      );

      return new WorkflowResponse(true);
    }
  );

How is that possible ?

It would be great to know how workflow actually work.

Expected behavior

Errors should be raised.

Actual behavior

Errors are not raised in workflow.

Link to reproduction repo

N/A

@kasperkristensen
Copy link
Contributor

Hi @Bradzer,

The docs on transform is very sparse right now, we will add some more documentation on how it works, and how to use it.

But in the meantime, in short:transform is not evaluated unless its passed to a step or the workflow response, which is why you aren't seeing your error being thrown, as the transform is never used. Transforms are not the best place to do validation, you should instead do so within a step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants