Decipher Groovy errors
When you develop Groovy queries, you eventually encounter errors. This guide teaches you how to read Groovy error output so you can find and fix problems quickly. For a short checklist, see Tips for reading errors.
The basics
Errors in Groovy fall into two categories:
- Compilation errors occur before execution, when the Groovy compiler rejects your script, for example because of invalid syntax or a class it can't resolve.
- Runtime exceptions occur during execution, when running code throws an exception. Errors in Deephaven formulas are runtime exceptions too, even when the message says "compilation": Deephaven compiles a formula only when your script calls the table operation that uses it.
Groovy errors appear as Java exception stack traces. Each at ... line in a trace is a frame: one method call, with the class, file, and line number it ran from. When one exception causes another, they chain together using Caused by: lines.
Read the log header
When code you run in the console fails, the console shows the stack trace. The IDE's Log panel shows the same error as a log entry. After the time and the log level, such as ERROR, the entry has a header that names where the error came from:
The header has two names, separated by |, and the message follows them. In the console examples below:
r-Scheduler-Serial-1is the thread that reported the error. It's the end ofDeephavenApiServer-Scheduler-Serial-1, the server thread that runs console commands..c.ConsoleServiceGrpcImplis the class that logged the error. It's the end ofi.d.s.c.ConsoleServiceGrpcImpl, the server class that handles console requests.Error running scriptstarts the message. It means the error came from running a console command.
The log shortens both names to fit fixed-width columns:
- The thread name keeps its last 20 characters.
- The class name keeps its last 25 characters. Before cutting the name, the log shortens package names to their initials, starting from the left, until the name fits or every package is an initial.
In the server's standard output, such as the Docker container output, each entry starts with the date and time in UTC, and the log level follows the thread name. Most traces on this page show only the header and the message.
Read a Groovy compilation error
As an example, let's run a line of code with a syntax error:
Click to see the full stack trace.
For compilation errors, Deephaven wraps the error in a GroovyExceptionWrapper. The key information is at the top of the output:
The line and column numbers show where the parser failed. Deephaven adds a package io.deephaven.dynamic; line before your code, so the reported line is one greater than the line in your editor.
In this example, the code never closes the parenthesis, so the parser keeps reading into the code that Deephaven appends after your script and fails there. As a result, the error reports line 5, which is past the end of your own code.
Note
Each time you execute code in the Deephaven console, Deephaven compiles it into a new class named Script_N. N increments only when an execution compiles successfully. A compilation error doesn't advance it, so the syntax error above and the next example both use Script_6.
This guide's traces come from more than one session, so their Script_N numbers don't always increase down the page. The numbers in your own traces differ from these.
The remainder of the trace shows frames from the Groovy compiler and from Deephaven's session infrastructure. You can generally ignore these frames. The useful signal is in the error message itself.
Read a runtime exception
Now let's look at a runtime exception. Here, a closure f throws when its argument is 10 or 20:
Click to see the full stack trace.
Because java.lang.Exception is a checked exception, Deephaven wraps it in a java.lang.RuntimeException before reporting it. Deephaven reports unchecked exceptions as is. Either way, follow the Caused by: chain to find the actual error.
A line such as ... 15 more at the end of a Caused by: block stands for frames that are the same as the last frames of the exception above it, so nothing is missing.
Tip
When a Groovy stack trace has Caused by: lines, the last Caused by: entry holds the root cause. Start there and work back toward the top.
Within the Caused by: block, look for frames in the io.deephaven.dynamic.Script_N class that cite Script_N.groovy. These frames point to your code.
Each line number counts from the start of the console command that defined the code. As with compilation errors, each line number is one greater than the line in your editor, because of the added package io.deephaven.dynamic; line. Here, line 3 is the throw inside f, and line 8 is the f(10) call:
Note
Groovy closures appear in stack traces as Script_N$_run_closureM, where M is a number based on the closure's position in the script. This is how the Groovy compiler names anonymous closures internally. A named method would appear as Script_N.methodName.
Now let's add another level of depth. The closure g calls f and accumulates the results:
Click to see the full stack trace.
Because you defined f and g in separate console executions, they live in different compiled classes: Script_6 and Script_7. The trace crosses those boundaries, showing the full call chain from the root cause upward:
Read an undefined-variable error
A common Groovy mistake is a misspelled variable name. In this example, the second line misspells t as tt. Here, i is the row index, one of Deephaven's special variables:
This output comes from the server's standard output, so the entry also has a timestamp and a log level, as Read the log header describes. Here are the first lines of the trace:
Reading this trace:
- No
Caused by:line: The full trace has none.MissingPropertyExceptionis an unchecked exception, so Deephaven reports it as is, without wrapping it. The exception on the first line is the root cause. - Message:
No such property: ttnames the variable that Groovy couldn't find.Script_9is the class that Deephaven compiled your command into. - Script line: The
Script_9.groovy:3frame points to the typo. It's one greater than the editor line (2) because Deephaven adds apackageline before your code.
To fix the error, correct the variable name, or define the variable before you use it.
Read a formula compilation error
Now let's look at a formula that references a column that doesn't exist. In the following example, f1 uses column X correctly, but f2 does not.
This is not a Groovy syntax error. The Groovy code is valid, but Deephaven fails to compile the formula Y = X * 3 when update runs. As The basics explains, the error therefore arrives as a runtime exception.
Click to see the full stack trace.
Working up the trace from the last Caused by: entry:
QueryLanguageParser$QueryLanguageParseException— the root cause. The Deephaven query language parser failed on the formula. Its message shows the full expression,X * 3, and the exact problem,Cannot find variable or class X.FormulaCompilationException: Formula compilation error for: X * 3— Deephaven could not compile the formula.
The frames that point to your code are Script_11$_run_closure2.doCall(Script_11.groovy:3) and Script_11.run(Script_11.groovy:5). The first is inside f2, at the update call. The second is the line that calls f2.
The _run_closure2 suffix marks the second closure defined in the script, which is f2. This confirms that f2 caused the problem.
This is a common mistake: a formula refers to a column that the table does not have. To fix it, create the column before the formula that uses it, as f1 does, or correct the column name in the formula.
Read a formula evaluation error
Sometimes a formula compiles, but code that it calls throws an exception during evaluation. The trace then depends on whether the table is static or ticking.
Static tables
You can use closures inside table formulas. When one throws, the trace chains more exceptions than a plain closure call does.
This example reuses the closure f from Read a runtime exception, which throws an exception when its argument is 10 or 20. Here, a column formula on a static table calls f:
Click to see the full stack trace.
Working up the trace from the last Caused by: entry:
java.lang.Exception: oops 1— the root cause. The closurefthrew it.FormulaEvaluationException: In formula: Y = f(X)— the query engine detected a failure while evaluating that formula.TableInitializationException: Error while initializing Update([Y])— the table failed to initialize because the formula failed.
The line Script_8.groovy:3 tells you which line in your code triggered the failing update call.
Ticking tables
A ticking table adds, modifies, or removes rows as new data arrives, so formula errors in it behave differently.
When you apply a formula to a ticking table, Deephaven evaluates it for the existing rows when it creates the table, then again for each added row and for each modified row whose input columns changed. Errors may appear well after the table is open and apparently working.
This example reuses the closure f from Read a runtime exception, which throws when its argument is 10 or 20. It applies f to a ticking table from timeTable, which adds one row per second:
The table runs for about ten seconds before it fails, when X reaches 10.
Click to see the full stack trace.
Several things differ from the static table error:
- Thread:
aph-updateExecutor-5instead ofr-Scheduler-Serial-1. The name is the end ofPeriodicUpdateGraph-updateExecutor-5, a thread of the update graph, not the thread that runs console commands. - Log source:
.AsyncClientErrorNotifier | Error in table update:instead of.c.ConsoleServiceGrpcImpl | Error running script. - First exception: The trace starts directly with
FormulaEvaluationException, with noTableInitializationException. Deephaven created the table successfully. The formula failed later, when a new row arrived. - Script line: No frame points to the line that created the table, because the error occurred asynchronously. The
Script_6$_run_closure1frame still points to thethrowinsidef.
In the IDE, the failed table's panel is covered by a warning icon and a message that begins with Unable to open table. The message gives an ID. Search the Deephaven logs for that ID to find the full error.
The next section shows the second log entry the server writes when a client is viewing the table, using a different formula.
Find a ticking-table error by its log ID
When a client such as the IDE is viewing a ticking table that fails, the server writes a second log entry, Internal Error '<id>', and sends the same ID to the client. The first entry is the Error in table update entry shown in Ticking tables.
In this example, a formula calls Math.floorDiv, which throws when its divisor reaches zero. In a Deephaven formula, / on integers returns a double, so dividing by zero gives Infinity instead of throwing.
The table runs without error at first. After about ten seconds, when X reaches zero, the table fails.
Click to see the full stack trace.
Reading this trace:
- Log entry:
SessionService, the server component that manages client sessions, writes this entry. The client receives a message that containsDetails Logged w/ID '<id>'with the same ID, so you can search the Deephaven logs for the full error. - Thread:
ph-updateExecutor-10, the end ofPeriodicUpdateGraph-updateExecutor-10. This is an update graph thread, as in Ticking tables. - Script line: None. As in Ticking tables, the error occurred asynchronously.
- Formula: The
In formula:text shows the column name and the formula expression,Y = Math.floorDiv((long)1, X), so you can match it to your code. - Root cause:
ArithmeticException: / by zero, at the end of theCaused by:chain.Math.floorDivthrew it whenXreached zero.
Tips for reading errors
The examples on this page follow the same steps:
- Find the error. Code you run in the console reports its error in the console. The full error for a ticking table appears only in the Deephaven logs, such as the IDE's Log panel.
- In the log, read the header.
Error running scriptmeans the error happened while the console ran your code. In the ticking-table examples, the header isError in table updateorInternal Error '<id>'instead, because the table failed later, while Deephaven updated it. - If the IDE shows an error message with an ID, such as
Details Logged w/ID '<id>', search the Deephaven logs for that ID. - For a
GroovyExceptionWrapper: startup failed:error, read the line and column in the message. The line is one greater than the line in your editor. If it points past the end of your code, look for a parenthesis or bracket that you didn't close. - For other errors, find the last
Caused by:entry. It holds the root cause. If the trace has noCaused by:line, the exception on the first line is the root cause. - Find the frames in
io.deephaven.dynamic.Script_Nclasses. They point to your code. Each line number counts from the start of the console command that defined that code and is one greater than the line in your editor. - Match the
In formula:orFull expressiontext to the formula in your code.
Related documentation
- Deephaven's table types
- Table operations overview
- Periodic Update Graph
- Query string overview
- Triage errors in queries
- Retrieve logs
- Groovy closures in queries
- Formulas
- Create static tables
- Create a time table
emptyTabletimeTableupdate- Special variables
GroovyExceptionWrapperJavadocFormulaCompilationExceptionJavadocFormulaEvaluationExceptionJavadocTableInitializationExceptionJavadoc