{"record":{"id":"c55c7dbcaadab16b","repo":"languagetool-org/languagetool","slug":"could-not-check-text-in-file-file","errorCode":null,"errorMessage":"Could not check text in file <file>","messagePattern":"Could not check text in file <file>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java","lineNumber":329,"sourceCode":"  private void runRecursive(String filename, String encoding, boolean xmlFiltering, JLanguageTool.Level level) {\n    File dir = new File(filename);\n    File[] files = dir.listFiles();\n    if (files == null) {\n      throw new IllegalArgumentException(dir.getAbsolutePath() + \" is not a directory, cannot use recursion\");\n    }\n    for (File file : files) {\n      try {\n        if (file.isDirectory()) {\n          runRecursive(file.getAbsolutePath(), encoding, xmlFiltering, level);\n        } else {\n          if (options.isLineByLine()) {\n            runOnFileLineByLine(file.getAbsolutePath(), encoding, level);\n          } else {\n            runOnFile(file.getAbsolutePath(), encoding, xmlFiltering);\n          }\n        }\n      } catch (Exception e) {\n        throw new RuntimeException(\"Could not check text in file \" + file, e);\n      }\n    }    \n  }\n\n  /**\n   * Loads filename and filters out XML. Note that the XML\n   * filtering can lead to incorrect positions in the list of matching rules.\n   */\n  private String getFilteredText(String filename, String encoding, boolean xmlFiltering) throws IOException {\n    if (options.isVerbose()) {\n      lt.setOutput(System.err);\n    }\n    // don't use StringTools.readStream() as that might add newlines which aren't there:\n    try (InputStreamReader reader = getInputStreamReader(filename, encoding)) {\n      String fileContents = readerToString(reader);\n      if (xmlFiltering) {\n        return filterXML(fileContents);\n      } else {","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java#L311-L347","documentation":"Main.runRecursive/runRecursiveFile wraps any Exception thrown while checking a file (or line within a file) into a RuntimeException with this message. It is a generic catch-all in the command-line client: whatever went wrong while reading or checking the file is preserved as the cause. It means LanguageTool could not complete the check of the given file.","triggerScenarios":"Running `languagetool` CLI with a file (or -r recursive directory) when an exception occurs inside runOnFile/runOnFileLineByLine: unreadable or non-UTF-8 file with wrong --encoding, malformed input, or any rule/loader exception during the check.","commonSituations":"Wrong --encoding option for the actual file encoding; file deleted or made unreadable between discovery and check; a broken custom rule or language module throwing during analysis; recursive scan hitting a binary/locked file.","solutions":["Read the 'Caused by' of the printed stack trace — this message only wraps the real failure.","Verify the --encoding flag matches the file's actual charset (e.g. UTF-8 vs ISO-8859-1).","Check the file is readable by the current user and not empty/corrupt (file, iconv, or head).","If running recursively, exclude binary/unwanted files and retry on the single failing file to isolate it."],"exampleFix":"// before\nlanguagetool -l en -c ASCII report.txt\n// after\nlanguagetool -l en -c UTF-8 report.txt","handlingStrategy":"try-catch","validationCode":"File f = new File(path);\nif (!f.isFile() || !f.canRead()) throw new IllegalArgumentException(\"unreadable file: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n  prg.runOnFile(file.getAbsolutePath(), encoding, xmlFiltering);\n} catch (RuntimeException e) {\n  log(\"File check failed: \" + file + \", cause=\" + e.getCause(), e);\n}","preventionTips":["Always pass --encoding matching the file's real charset.","Validate file readability before invoking the CLI.","Exclude binary files from recursive runs."],"tags":["cli","file-io","encoding","runtime-exception"],"backgroundTag":"file-read-failed","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}