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

  1. Verify the tsurgeon script file/resource exists and is non-empty before loading
  2. Check that the Reader is opened on the correct file path or classpath resource
  3. Print/inspect the raw input stream contents to confirm operations are present
  4. 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

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


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 helpful

View on GitHub (pinned to 1b7edd19c4)