Why this simple code returns a wrong string?

export default defineComponent({
  async run({ steps }) {
    if(steps.weekend) return process.env.MSG_WEEKEND;
    if(!steps.upcoming) return process.env.MSG_CANCELED;
    return process.env.MSG_SUCCESS;
  },
})

Here steps.weekend is false and steps.upcoming is true.
Why does this code return MSG_WEEKEND?
Here is the screenshot:

Hi @slishnevsky,

The code you provided should not return MSG_WEEKEND if steps.weekend is false and steps.upcoming is true. According to the logic in your code:

  1. If steps.weekend is true, it should return process.env.MSG_WEEKEND.
  2. If steps.upcoming is false, it should return process.env.MSG_CANCELED.
  3. Otherwise, it should return process.env.MSG_SUCCESS.

Given that steps.weekend is false and steps.upcoming is true, the code should return process.env.MSG_SUCCESS.

Here’s the code for reference:

export default defineComponent({
  async run({ steps }) {
    if (steps.weekend) return process.env.MSG_WEEKEND;
    if (!steps.upcoming) return process.env.MSG_CANCELED;
    return process.env.MSG_SUCCESS;
  },
});

If the code is returning MSG_WEEKEND, it suggests that steps.weekend is being evaluated as true. This could be due to a few reasons:

  1. Incorrect Value in steps.weekend: Ensure that steps.weekend is indeed false. You can add a console.log statement to debug the value:

    export default defineComponent({
      async run({ steps }) {
        console.log("steps.weekend:", steps.weekend);
        console.log("steps.upcoming:", steps.upcoming);
        if (steps.weekend) return process.env.MSG_WEEKEND;
        if (!steps.upcoming) return process.env.MSG_CANCELED;
        return process.env.MSG_SUCCESS;
      },
    });
    
  2. Falsy Values: Ensure that steps.weekend is not set to a falsy value that is being interpreted as true. For example, a string "false" is truthy in JavaScript.

  3. Environment Variables: Double-check the environment variables to ensure they are set correctly.

Please verify the values of steps.weekend and steps.upcoming by logging them and ensure they are as expected. If the issue persists, please provide more details or screenshots of the values being passed to the steps object.

I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double-check my answers and code! Learn how to build your own.

As I said,
steps.weekend is false and steps.upcoming is true.
So, it should return MSG_SUCCESS.
Instead, it returns MSG_WEEKEND.

I think you’re missing the return value: steps.weekend.$return_value