stanfordnlp/CoreNLP · error · TsurgeonParseException
No Tsurgeon operation provided.
Error message
No Tsurgeon operation provided.
What it means
Tsurgeon.getTsurgeonOperationsFromReader reads tsurgeon operation blocks from a Reader, pairing each tregex pattern with its operation. If the reader yields no operations at all (empty input), it throws TsurgeonParseException("No Tsurgeon operation provided.") because there is nothing to collect into an operation sequence.
Solutions
- Verify the tsurgeon script file/resource exists and is non-empty before loading
- Check that the Reader is opened on the correct file path or classpath resource
- Print/inspect the raw input stream contents to confirm operations are present
- Catch TsurgeonParseException and provide a default operation set or clear user-facing message
Example fix
// before
List<TsurgeonPattern> ops = Tsurgeon.getTsurgeonOperationsFromReader(new BufferedReader(new FileReader(scriptFile)));
// after
if (!scriptFile.exists() || scriptFile.length() == 0) {
throw new IllegalArgumentException("Tsurgeon script is missing or empty: " + scriptFile);
}
List<TsurgeonPattern> ops = Tsurgeon.getTsurgeonOperationsFromReader(new BufferedReader(new FileReader(scriptFile))); Defensive patterns
Strategy: validation
Validate before calling
File script = new File(path);
if (!script.isFile() || script.length() == 0) {
throw new IllegalArgumentException("Tsurgeon script missing or empty: " + path);
} Try / catch
try (BufferedReader r = new BufferedReader(new FileReader(script))) {
ops = Tsurgeon.getTsurgeonOperationsFromReader(r);
} catch (TsurgeonParseException e) {
throw new IllegalStateException("No tsurgeon operations loaded from " + script, e);
} Prevention
- Check script file exists and is non-empty before loading
- Verify classpath resource names when loading from jars
- Log the raw script content at load time to catch empty pipelines
When it happens
Trigger: Passing an empty Reader, an empty file, or a file containing only blank lines/comments to Tsurgeon.getTsurgeonOperationsFromReader (e.g. via the collectedPattern path that loads tsurgeon scripts).
Common situations: Tsurgeon script file path resolved to an empty file; resource stream misconfigured (e.g. wrong classpath resource); shell pipeline or variable expansion produced empty input; reading a file before it was written.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Error parsing Tsurgeon expression: " + operationString
- Illegal number of nodes given to createSubtree (" +…
- annotator " " requires annotation " ". The usual…
- : Entry doesn't have overwriteable types , but entry type…
- : Ignoring duplicate entry: , old type = , new type =
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/00a91e9b57b58bbc.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/tregex/tsurgeon/Tsurgeon.java:491
*
* @throws IOException If the usual kinds of IO errors occur
*/
public static TsurgeonPattern getTsurgeonOperationsFromReader(BufferedReader reader) throws IOException {
List<TsurgeonPattern> operations = new ArrayList<>();
for (String thisLine; (thisLine = reader.readLine()) != null; ) {
if (emptyLinePattern.matcher(thisLine).matches()) {
break;
}
thisLine = removeComments(thisLine);
if (emptyLinePattern.matcher(thisLine).matches()) {
continue;
}
// log.info("Read tsurgeon op: " + thisLine);
operations.add(parseOperation(thisLine));
}
if (operations.isEmpty()) {
throw new TsurgeonParseException("No Tsurgeon operation provided.");
}
return collectOperations(operations);
}
private static String removeComments(String line) {
Matcher m = commentPattern.matcher(line);
line = m.replaceFirst("");
Matcher m1 = escapedCommentCharacterPattern.matcher(line);
line = m1.replaceAll(commentIntroducingCharacter);
return line;
}
/**
* Assumes the given reader has only tsurgeon operations (not a tregex pattern), and returns
* them as a String, mirroring the way the strings appear in the file. This is helpfulView on GitHub (pinned to 1b7edd19c4)