# Painless scripting error illegal\_argument\_exception "unexpected token \['('\] was expecting one of \[{\<EOF\>, ';'}\]"

**URL:** https://discuss.elastic.co/t/painless-scripting-error-illegal-argument-exception-unexpected-token-was-expecting-one-of-eof/135547
**Category:** Elasticsearch
**Created:** [June 12, 2018, 1:37pm UTC](https://discuss.elastic.co/t/painless-scripting-error-illegal-argument-exception-unexpected-token-was-expecting-one-of-eof/135547 "2018-06-12T13:37:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ajp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajp/32/32182_2.png) [@ajp](https://discuss.elastic.co/u/ajp)
#### Post date: [June 12, 2018, 1:37pm UTC](https://discuss.elastic.co/t/painless-scripting-error-illegal-argument-exception-unexpected-token-was-expecting-one-of-eof/135547/1 "2018-06-12T13:37:14Z")

</div>

Running the following painless script against 6.2.4 returns an illegal\_argument\_exception "unexpected token ['('] was expecting one of [{, ';'}]".

```
def someVariable = "";

void someFunction(def arg) {
    def someVariable2 = "";
}

someFunction("");

```

It doesn't error if you use the following script:

```
void someFunction(def arg) {
    def someVariable2 = "";
}

def someVariable = "";

someFunction("");

```

I tried searching both the open and closed GitHub issues and the forum here but can't find anything similar mentioned. I was wondering if anyone could:

- point out my error
- confirm this is a bug (by reproducing it) and or
- point me to the bug report

I'm happy to open a new bug report on Github if this turns out to be a real issue.

Thank you for your time.

---

<div class="post-metadata">

### Author: ![ajp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajp/32/32182_2.png) [@ajp](https://discuss.elastic.co/u/ajp)
#### Post date: [July 2, 2018, 4:53pm UTC](https://discuss.elastic.co/t/painless-scripting-error-illegal-argument-exception-unexpected-token-was-expecting-one-of-eof/135547/2 "2018-07-02T16:53:43Z")

</div>

It seems that all variables need to be declared and defined after all functions. In this case if `someVariable` is desired inside `someFunction` then you must pass it in as a parameter. For example:

```
String someFunction(def arg, String someVariable) {
  return arg + someVariable;
}

String someVariable = "";

someFunction("", someVariable);
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 30, 2018, 4:53pm UTC](https://discuss.elastic.co/t/painless-scripting-error-illegal-argument-exception-unexpected-token-was-expecting-one-of-eof/135547/3 "2018-07-30T16:53:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
