Watcher: Ensure awesome painless exceptions are propagated to the user (elastic/elasticsearch#3707)
When adding a watch which has a painless component, the scriptexception was wrapped into a deprecated exception which means, that the awesome painless descriptions were lost. This wrapping has been removed. Closes elastic/elasticsearch#3161 Original commit: elastic/x-pack-elasticsearch@1703fe4eb6
This commit is contained in:
parent
4c6e42ca2d
commit
8b83cf067c
|
@ -31,13 +31,9 @@ public class ExecutableScriptCondition extends ExecutableCondition<ScriptConditi
|
|||
public ExecutableScriptCondition(ScriptCondition condition, Logger logger, ScriptService scriptService) {
|
||||
super(condition, logger);
|
||||
this.scriptService = scriptService;
|
||||
try {
|
||||
Script script = new Script(condition.script.getScript(), condition.script.getType(),
|
||||
condition.script.getLang(), condition.script.getParams());
|
||||
compiledScript = scriptService.compile(script, Watcher.SCRIPT_CONTEXT, Collections.emptyMap());
|
||||
} catch (Exception e) {
|
||||
throw invalidScript("failed to compile script [{}]", e, condition.script, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -171,7 +171,7 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
parser.nextToken();
|
||||
ScriptCondition scriptCondition = conditionParser.parseCondition("_watch", parser, false);
|
||||
expectThrows(GeneralScriptException.class,
|
||||
expectThrows(IllegalArgumentException.class,
|
||||
() -> conditionParser.createExecutable(scriptCondition));
|
||||
}
|
||||
|
||||
|
@ -182,9 +182,9 @@ public class ScriptConditionTests extends ESTestCase {
|
|||
XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes());
|
||||
parser.nextToken();
|
||||
ScriptCondition scriptCondition = conditionParser.parseCondition("_watch", parser, false);
|
||||
GeneralScriptException exception = expectThrows(GeneralScriptException.class,
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
||||
() -> conditionParser.createExecutable(scriptCondition));
|
||||
assertThat(exception.getMessage(), containsString("script_lang not supported [not_a_valid_lang]]"));
|
||||
assertThat(exception.getMessage(), containsString("script_lang not supported [not_a_valid_lang]"));
|
||||
}
|
||||
|
||||
public void testScriptConditionThrowException() throws Exception {
|
||||
|
|
|
@ -8,16 +8,15 @@ package org.elasticsearch.xpack.watcher.test.integration;
|
|||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.common.http.auth.basic.ApplicableBasicAuth;
|
||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchResponse;
|
||||
|
@ -29,7 +28,6 @@ import org.joda.time.DateTime;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.net.BindException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
@ -62,16 +60,8 @@ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestC
|
|||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
for (int webPort = 9200; webPort < 9300; webPort++) {
|
||||
try {
|
||||
webServer = new MockWebServer();
|
||||
webServer.start(webPort);
|
||||
return;
|
||||
} catch (BindException be) {
|
||||
logger.warn("port [{}] was already in use trying next port", webPort);
|
||||
}
|
||||
}
|
||||
throw new ElasticsearchException("unable to find open port between 9200 and 9300");
|
||||
webServer.start();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
"Test awesome painless exceptions are returned including the script_stack field":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
catch: request
|
||||
xpack.watcher.put_watch:
|
||||
id: "my_exe_watch"
|
||||
body: >
|
||||
{
|
||||
"trigger" : {
|
||||
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
|
||||
},
|
||||
"input" : {
|
||||
"simple" : {}
|
||||
},
|
||||
"condition" : {
|
||||
"script" : {
|
||||
"inline" : "FOO == 1",
|
||||
"lang" : "painless"
|
||||
}
|
||||
},
|
||||
"actions" : {
|
||||
"email_admin" : {
|
||||
"email" : {
|
||||
"to" : "someone@domain.host.com",
|
||||
"subject" : "404 recently encountered"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- is_true: error.script_stack
|
||||
- match: { status: 500 }
|
Loading…
Reference in New Issue