---
"Test awesome painless exceptions are returned including the script_stack field":
  - do:
      cluster.health:
          wait_for_status: green

  - do:
      catch: bad_request
      watcher.put_watch:
        id: "my_exe_watch"
        body:  >
          {
            "trigger" : {
              "schedule" : { "cron" : "0 0 0 1 * ? 2099" }
            },
            "input" : {
              "simple" : {}
            },
            "condition" : {
              "script" : {
                "source" : "FOO == 1",
                "lang" : "painless"
              }
            },
            "actions" : {
              "email_admin" : {
                "email" : {
                  "to" : "someone@domain.host.com",
                  "subject" : "404 recently encountered"
                }
              }
            }
          }

  - is_true: error.script_stack
  - match: { status: 400 }

---
"Test painless exceptions are returned when logging a broken response":
  - skip:
      known_issues:
        - cluster_feature: "gte_v8.7.0"
          fixed_by: "gte_v8.7.2"
      reason: "self-referencing objects were in Painless instead of Mustache in 8.7.0 to 8.7.1"

  - do:
      cluster.health:
          wait_for_status: green

  - do:
      watcher.execute_watch:
        body:  >
          {
            "watch" : {
              "trigger": {
                "schedule": {
                  "interval": "1d"
                }
              },
              "input": {
                "simple": {
                  "foo": "bar"
                }
              },
              "actions": {
                "my-logging": {
                  "transform": {
                    "script": {
                      "source": "def x = [:] ; def y = [:] ; x.a = y ; y.a = x ; return x"
                    }
                  },
                  "logging": {
                    "text": "{{ctx}}"
                  }
                }
              }
            }
          }

  - match: { watch_record.watch_id: "_inlined_" }
  - match: { watch_record.trigger_event.type: "manual" }
  - match: { watch_record.state: "executed" }
  - match: { watch_record.result.actions.0.transform.status: "failure" }
  - match: { watch_record.result.actions.0.transform.error.type: "illegal_argument_exception" }
  - match: { watch_record.result.actions.0.transform.error.reason: "Iterable object is self-referencing itself (watcher action payload)" }
