{"record":{"id":"52c4d0c6ac2637d4","repo":"alibaba/spring-ai-alibaba","slug":"path-is-not-a-directory","errorCode":null,"errorMessage":"Path is not a directory: ","messagePattern":"Path is not a directory: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/task/AgentSpecLoader.java","lineNumber":84,"sourceCode":"\t * @return list of parsed specs\n\t */\n\tpublic static List<AgentSpec> loadFromDirectory(String directoryPath) throws IOException {\n\t\tif (!StringUtils.hasText(directoryPath)) {\n\t\t\treturn List.of();\n\t\t}\n\t\treturn loadFromDirectory(Paths.get(directoryPath));\n\t}\n\n\t/**\n\t * Load agent specs from a directory (recursively scans for .md files).\n\t */\n\tpublic static List<AgentSpec> loadFromDirectory(Path rootPath) throws IOException {\n\t\tif (rootPath == null || !Files.exists(rootPath)) {\n\t\t\tlogger.warn(\"Agent spec directory does not exist: {}\", rootPath);\n\t\t\treturn List.of();\n\t\t}\n\t\tif (!Files.isDirectory(rootPath)) {\n\t\t\tthrow new IOException(\"Path is not a directory: \" + rootPath);\n\t\t}\n\n\t\tList<AgentSpec> specs = new ArrayList<>();\n\t\ttry (Stream<Path> paths = Files.walk(rootPath)) {\n\t\t\tpaths.filter(Files::isRegularFile)\n\t\t\t\t\t.filter(p -> p.getFileName().toString().endsWith(\".md\"))\n\t\t\t\t\t.forEach(path -> {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tAgentSpec spec = loadFromFile(path);\n\t\t\t\t\t\t\tif (spec != null) {\n\t\t\t\t\t\t\t\tspecs.add(spec);\n\t\t\t\t\t\t\t\tlogger.debug(\"Loaded agent spec: {} from {}\", spec.name(), path);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\t\tlogger.warn(\"Failed to load agent spec from {}: {}\", path, e.getMessage());\n\t\t\t\t\t\t}\n\t\t\t\t\t});","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/task/AgentSpecLoader.java#L66-L102","documentation":"AgentSpecLoader.loadFromDirectory requires the given Path to be an existing directory containing .md agent spec files. If the path exists but is a regular file (or another non-directory type), an IOException with 'Path is not a directory: ...' is thrown. This is a fail-fast guard before walking the tree.","triggerScenarios":"Calling AgentSpecLoader.loadFromDirectory(path) where Files.exists(path) is true but Files.isDirectory(path) is false — e.g. passing a single .md file path instead of the spec directory.","commonSituations":"Developers point the loader at one agent markdown file instead of its folder; a config property meant to hold a directory accidentally contains a file path; symlinks resolve to files.","solutions":["Pass the directory containing the .md agent spec files, not an individual file.","Validate with Files.isDirectory(path) before calling; if you need to load a single file, use AgentSpecLoader.loadFromResource instead.","Check the configured path property in application config for typos or accidental file paths."],"exampleFix":"// before\nList<AgentSpec> specs = AgentSpecLoader.loadFromDirectory(Path.of(\"agents/spec.md\"));\n// after\nList<AgentSpec> specs = AgentSpecLoader.loadFromDirectory(Path.of(\"agents/\"));","handlingStrategy":"validation","validationCode":"if (path == null || !Files.isDirectory(path)) throw new IllegalArgumentException(\"Expected a directory: \" + path);","typeGuard":"boolean isSpecDir(Path p) { return p != null && Files.isDirectory(p); }","tryCatchPattern":null,"preventionTips":["Store directory paths, not file paths, in agent spec configuration.","Add a startup check that logs and fails fast if the spec path is not a directory.","Use loadFromResource for individual .md files."],"tags":["io","agent-spec","file-loading"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}