Search in sources :

Example 1 with ScriptException

use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.

the class ExpressionFieldScriptTests method testCompileError.

public void testCompileError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['field'].value * *@#)(@$*@#$ + 4");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.opensearch.script.ScriptException) ParseException(java.text.ParseException)

Example 2 with ScriptException

use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.

the class ExpressionFieldScriptTests method testLinkError.

public void testLinkError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['nonexistent'].value * 5");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.opensearch.script.ScriptException) ParseException(java.text.ParseException)

Example 3 with ScriptException

use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.

the class ExpressionTermsSetQueryTests method testLinkError.

public void testLinkError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['nonexistent'].value * 5");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.opensearch.script.ScriptException) ParseException(java.text.ParseException)

Example 4 with ScriptException

use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.

the class ExpressionTermsSetQueryTests method testCompileError.

public void testCompileError() {
    ScriptException e = expectThrows(ScriptException.class, () -> {
        compile("doc['field'].value * *@#)(@$*@#$ + 4");
    });
    assertTrue(e.getCause() instanceof ParseException);
}
Also used : ScriptException(org.opensearch.script.ScriptException) ParseException(java.text.ParseException)

Example 5 with ScriptException

use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.

the class DebugTests method testPainlessExplainErrorSerialization.

/**
 * {@link PainlessExplainError} doesn't serialize but the headers still make it.
 */
public void testPainlessExplainErrorSerialization() throws IOException {
    Map<String, Object> params = singletonMap("a", "jumped over the moon");
    ScriptException e = expectThrows(ScriptException.class, () -> exec("Debug.explain(params.a)", params, true));
    assertEquals(singletonList("jumped over the moon"), e.getMetadata("opensearch.to_string"));
    assertEquals(singletonList("java.lang.String"), e.getMetadata("opensearch.java_class"));
    assertEquals(singletonList("java.lang.String"), e.getMetadata("opensearch.painless_class"));
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        out.writeException(e);
        try (StreamInput in = out.bytes().streamInput()) {
            OpenSearchException read = (ScriptException) in.readException();
            assertEquals(singletonList("jumped over the moon"), read.getMetadata("opensearch.to_string"));
            assertEquals(singletonList("java.lang.String"), read.getMetadata("opensearch.java_class"));
            assertEquals(singletonList("java.lang.String"), read.getMetadata("opensearch.painless_class"));
        }
    }
}
Also used : ScriptException(org.opensearch.script.ScriptException) StreamInput(org.opensearch.common.io.stream.StreamInput) OpenSearchException(org.opensearch.OpenSearchException) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

ScriptException (org.opensearch.script.ScriptException)18 ParseException (java.text.ParseException)8 Map (java.util.Map)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Script (org.opensearch.script.Script)3 ScriptService (org.opensearch.script.ScriptService)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)2 IngestConditionalScript (org.opensearch.script.IngestConditionalScript)2 MockScriptService (org.opensearch.script.MockScriptService)2 Mustache (com.github.mustachejava.Mustache)1 MustacheException (com.github.mustachejava.MustacheException)1 MustacheFactory (com.github.mustachejava.MustacheFactory)1 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1