{"record":{"id":"00a91e9b57b58bbc","repo":"stanfordnlp/CoreNLP","slug":"no-tsurgeon-operation-provided","errorCode":null,"errorMessage":"No Tsurgeon operation provided.","messagePattern":"No Tsurgeon operation provided\\.","errorType":"exception","errorClass":"TsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/tregex/tsurgeon/Tsurgeon.java","lineNumber":491,"sourceCode":"   *\n   * @throws IOException If the usual kinds of IO errors occur\n   */\n  public static TsurgeonPattern getTsurgeonOperationsFromReader(BufferedReader reader) throws IOException {\n    List<TsurgeonPattern> operations = new ArrayList<>();\n    for (String thisLine; (thisLine = reader.readLine()) != null; ) {\n      if (emptyLinePattern.matcher(thisLine).matches()) {\n        break;\n      }\n      thisLine = removeComments(thisLine);\n      if (emptyLinePattern.matcher(thisLine).matches()) {\n        continue;\n      }\n      // log.info(\"Read tsurgeon op: \" + thisLine);\n      operations.add(parseOperation(thisLine));\n    }\n\n    if (operations.isEmpty()) {\n      throw new TsurgeonParseException(\"No Tsurgeon operation provided.\");\n    }\n\n    return collectOperations(operations);\n  }\n\n\n  private static String removeComments(String line) {\n    Matcher m = commentPattern.matcher(line);\n    line = m.replaceFirst(\"\");\n    Matcher m1 = escapedCommentCharacterPattern.matcher(line);\n    line = m1.replaceAll(commentIntroducingCharacter);\n    return line;\n  }\n\n\n  /**\n   * Assumes the given reader has only tsurgeon operations (not a tregex pattern), and returns\n   * them as a String, mirroring the way the strings appear in the file. This is helpful","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/tsurgeon/Tsurgeon.java#L473-L509","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nList<TsurgeonPattern> ops = Tsurgeon.getTsurgeonOperationsFromReader(new BufferedReader(new FileReader(scriptFile)));\n// after\nif (!scriptFile.exists() || scriptFile.length() == 0) {\n  throw new IllegalArgumentException(\"Tsurgeon script is missing or empty: \" + scriptFile);\n}\nList<TsurgeonPattern> ops = Tsurgeon.getTsurgeonOperationsFromReader(new BufferedReader(new FileReader(scriptFile)));","handlingStrategy":"validation","validationCode":"File script = new File(path);\nif (!script.isFile() || script.length() == 0) {\n  throw new IllegalArgumentException(\"Tsurgeon script missing or empty: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try (BufferedReader r = new BufferedReader(new FileReader(script))) {\n  ops = Tsurgeon.getTsurgeonOperationsFromReader(r);\n} catch (TsurgeonParseException e) {\n  throw new IllegalStateException(\"No tsurgeon operations loaded from \" + script, e);\n}","preventionTips":["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"],"tags":["tsurgeon","empty-input","parse-error","configuration"],"backgroundTag":"empty-required-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}