Skip to content

ResultPath not getting set when calling context.sendTaskSuccess with a zero. #406

@alexd-garcia

Description

@alexd-garcia

Hello,

I noticed that when the call to context.sendTaskSuccess is a zero the result path is not getting set. The following example shows the error.

const Statebox = require('@wmfs/statebox')
const statebox = new Statebox({})

const main = async

function() {
  await statebox.ready
  statebox.createModuleResources({
    // Simple module to add two numbers together
    add: class Add {
      run(event, context) {
        context.sendTaskSuccess(event.number1 + event.number2)
      }
    },
    // Simple module to subtract one number from another
    subtract: class Subtract {
      // Init methods are optional, but all allow
      // resource-instances to be configured...
      init(resourceConfig, env, callback) {
        callback(null)
      }
      run(event, context) {
        context.sendTaskSuccess(event.number1 - event.number2)
      }
    }
  })
  await statebox.createStateMachines({
      'calculator': {
        Comment: 'A simple calculator',
        StartAt: 'Subtract',
        States: {
          Subtract: {
            Type: 'Task',
            InputPath: '$.numbers',
            Resource: 'module:subtract',
            ResultPath: '$.result',
            End: true
          }
        }
      }
    }, {}, // 'env': An environment/context/sandbox
  )

  // STEP 3:
  // Start a new execution on a state machine
  // ----------------------------------------
  const executionDescription = await statebox.startExecution({
      numbers: {
        number1: 3,
        number2: 3
      }
    }, // input
    'calculator', // state machine name
    {} // options
  )

  console.log(executionDescription)
  // {
  //   executionName: '...',
  //   ctx: {
  //     numbers': {
  //       number1: 3,
  //       number2: 2
  //     },
  //     operator: '-',
  //     result: 0 <--- This is not getting set in the context
  //   },
  // }
}

if (require.main === module) {
  main();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions