{"record":{"id":"886371a7ab082bf5","repo":"alibaba/spring-ai-alibaba","slug":"config-folder-does-not-exist","errorCode":null,"errorMessage":"Config folder does not exist: ","messagePattern":"Config folder does not exist: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/loader/ConfigAgentWatcher.java","lineNumber":98,"sourceCode":"\t\t}\n\t\tcatch (InterruptedException e) {\n\t\t\tfileWatcher.shutdownNow();\n\t\t\tThread.currentThread().interrupt();\n\t\t}\n\t\tstarted = false;\n\t\tlogger.info(\"ConfigAgentWatcher stopped.\");\n\t}\n\n\t/**\n\t * Adds a folder to be watched for changes to any YAML files within it.\n\t *\n\t * @param agentDirPath The path to the agent configuration directory\n\t * @param callback The callback to invoke when changes are detected\n\t * @throws IllegalArgumentException if the folder doesn't exist\n\t */\n\tvoid watch(Path agentDirPath, ChangeCallback callback) {\n\t\tif (!Files.isDirectory(agentDirPath)) {\n\t\t\tthrow new IllegalArgumentException(\"Config folder does not exist: \" + agentDirPath);\n\t\t}\n\n\t\twatchedFolders.put(agentDirPath, callback);\n\n\t\t// Scan and track all YAML files in the directory\n\t\tMap<Path, Long> yamlFiles = scanYamlFiles(agentDirPath);\n\t\twatchedYamlFiles.put(agentDirPath, yamlFiles);\n\n\t\tlogger.debug(\"Now watching {} YAML files in agent folder: {}\", yamlFiles.size(), agentDirPath);\n\t}\n\n\t/**\n\t * Scans a directory recursively for all YAML files and returns their last modified times.\n\t *\n\t * @param agentDirPath The directory to scan recursively\n\t * @return A map of YAML file paths to their last modified times\n\t */\n\tprivate Map<Path, Long> scanYamlFiles(Path agentDirPath) {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/loader/ConfigAgentWatcher.java#L80-L116","documentation":"ConfigAgentWatcher.watch(Path agentDirPath, ChangeCallback callback) throws IllegalArgumentException when the given path is not an existing directory (Files.isDirectory returns false). The watcher only supports watching real directories of YAML agent configs. The path may be missing, be a regular file, or be unreadable such that it doesn't present as a directory.","triggerScenarios":"Calling watch() with a path that does not exist, points to a file instead of a directory, uses a wrong relative path (resolved against the wrong working directory), or references a deleted/moved config folder.","commonSituations":"Hardcoded path like ./config/agents that doesn't exist in the deployment environment; running the app from a different working directory so relative paths resolve differently; container image missing the config directory; typo in the configured agent dir path.","solutions":["Create the directory before watching: Files.createDirectories(agentDirPath)","Use an absolute path or verify the process working directory so the relative path resolves correctly","Check the configured path points to a directory, not a YAML file (pass the parent dir instead)","In containers/k8s, verify the config volume is mounted at the expected path"],"exampleFix":"// before\nwatcher.watch(Path.of(\"config/agents\"), callback); // fails if dir absent\n// after\nPath dir = Path.of(\"config/agents\").toAbsolutePath();\nFiles.createDirectories(dir);\nwatcher.watch(dir, callback);","handlingStrategy":"validation","validationCode":"Path dir = agentDirPath == null ? null : agentDirPath.toAbsolutePath();\nif (dir == null || !Files.isDirectory(dir)) {\n    throw new IllegalArgumentException(\"Agent config dir must exist and be a directory: \" + dir);\n}","typeGuard":null,"tryCatchPattern":"try {\n    watcher.watch(dir, callback);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Config dir invalid: {}\", e.getMessage());\n    Files.createDirectories(dir);\n    watcher.watch(dir, callback);\n}","preventionTips":["Call Files.createDirectories() on the configured path before watching","Use absolute paths or anchor relative paths to a known base directory","In containerized deployments, verify the config volume is mounted before application startup","Point watch() at the directory containing YAML files, not at an individual file"],"tags":["java","illegal-argument","directory-not-found","file-watcher"],"backgroundTag":"directory-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}