alibaba/spring-ai-alibaba · error · RuntimeException
Failed to parse test file
Error message
Failed to parse test file: {file} What it means
DocumentExtractorNode.getDocument throws this RuntimeException when extracting text from a file in the file list fails — the input stream could not be opened or extractTextByFileExtension could not parse the content for that file's extension. The original exception is wrapped with the offending file path.
Solutions
- Read the wrapped cause to identify whether it's an open failure or parse failure
- Fix the file's extension or convert it to a supported format
- Verify the file exists/is accessible at extraction time (check URLs, permissions)
- Pre-validate files (existence + extension) before running the workflow
Example fix
// before
files.add("/data/report.pdf.txt"); // wrong extension
// after
files.add("/data/report.pdf"); Defensive patterns
Strategy: try-catch
Validate before calling
for (String f : files) {
try (InputStream in = getInputStream(f)) { /* probe readable */ }
catch (Exception e) { throw new PrecheckException("unreadable file: " + f, e); }
} Try / catch
try {
result = extractorNode.apply(state);
} catch (RuntimeException e) {
logger.error("Extraction failed: {}", e.getMessage(), e.getCause());
state.put(outputKey, List.of());
} Prevention
- Pre-validate file existence, permissions, and extension before extraction
- Keep file extensions accurate and convert unsupported formats upstream
- Read the wrapped cause — it distinguishes open failures from parse failures
When it happens
Trigger: A file listed in the state's file list cannot be read (missing resource, bad URL/path, permission) or its extension does not match its actual format so the Tika/extension-based parser fails.
Common situations: Unsupported or misnamed extensions (.docx passed as .txt); files uploaded as ArraryFileSegment with broken URLs; temporary files deleted before extraction; network-hosted files unreachable at parse time.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to read resource
- File variable not found for selector
- Unsupported Extension Type
- Variable fileList is not an ArrayFileSegment
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/fb37df835203bb8d.
Report an issue: GitHub.
Appendix: source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/DocumentExtractorNode.java:110
else {
uri = Paths.get(filePath).toUri();
}
if (uri.getScheme().equals("file")) {
return new BufferedInputStream(Files.newInputStream(Paths.get(uri)));
}
else {
return new BufferedInputStream(uri.toURL().openStream());
}
}
private List<String> getDocument(List<String> fileList) {
return fileList.stream().map(String::trim).map(file -> {
try (InputStream inputStream = this.getInputStream(file.trim())) {
return this.extractTextByFileExtension(inputStream, getFileExtension(file));
}
catch (Exception e) {
throw new RuntimeException("Failed to parse test file: " + file, e);
}
}).toList();
}
@Override
public Map<String, Object> apply(OverAllState state) throws Exception {
if (paramsKey == null && fileList == null) {
throw new RuntimeException("File variable not found for selector");
}
List<String> fileList;
Object fileObj = state.value(paramsKey).orElse(this.fileList);
if (this.inputIsArray) {
if (fileObj instanceof List<?>) {
fileList = (List<String>) fileObj;
}
else if (fileObj instanceof String[]) {
fileList = Arrays.asList((String[]) fileObj);
}View on GitHub (pinned to f82da0b50f)