StackStorm / st2flow

DEPRECATED & OBSOLETE! Previously StackStorm Enterprise (EWC) Workflow Editor. Now integrated directly into StackStorm OSS Core platform (st2web).
https://github.com/StackStorm/st2web/
Apache License 2.0
16 stars 6 forks source link

Using a YAQL templating string instead of a list causes the entire web UI to crash #386

Open miyoyo opened 4 years ago

miyoyo commented 4 years ago

Currently, when passing something such as:

  notify_user:
    action: msexchange.send_email
    input:
      log_level: DEBUG
      body: "<% ctx().email_body %>"
      subject: "<% ctx().subject %>"
      to_recipients: <% ctx().to_recipients %>

Where to_recipients expects a list, even if the YAQL query returns a list, react fails to render and the screen goes permanently white until a full page reload.

The error happens here: https://github.com/StackStorm/st2flow/blob/d7490794f78fb3f720d16b685464e1ace93615be/modules/st2-auto-form/fields/array.js#L101

image

The exact error is image

From what I understand, the method just does not expect that v could be a bad string.

A quick fix would be to do a type check before attempting to return a value.

  toStateValue(v) {
    if (jsonCheck(v)) {
      return JSON.stringify(v);
    }

    if (isJinja(v)) {
      return v;
    }

    const { secret } = this.props.spec || {};
    if (secret && v && !Array.isArray(v)) {
      return v;
    }

    if(v == null) {
        return '';
    }

    if(!Array.isArray(v)) {
      // "Invalid Value"
    }

    return v.join(', ');
  }