{"record":{"id":"764d00422d455084","repo":"iflytek/astron-agent","slug":"file-s-not-exit-in-dir-s","errorCode":null,"errorMessage":"file %s not exit in dir %s","messagePattern":"file (.+?) not exit in dir (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/plugin/link/utils/json_schemas/read_json_schemas.py","lineNumber":171,"sourceCode":"    \"\"\"\n\n    def __init__(self, dir_path: str):\n        \"\"\"\n        description: Initialize\n        :param dir_path:\n        \"\"\"\n        self.path = dir_path\n\n    def __call__(self, file: str) -> str:\n        \"\"\"\n        description: Synchronous call, read file information\n        :return:\n        \"\"\"\n        if not file.endswith(\".json\"):\n            raise Exception(\"file %s suffix not .json\" % file)\n        schema_info = None\n        if not os.path.exists(os.path.join(self.path, file)):\n            raise Exception(\"file %s not exit in dir %s\" % (file, self.path))\n        with open(os.path.join(self.path, file), encoding=\"utf8\") as file_handle:\n            schema_info = file_handle.read()\n\n        if not schema_info:\n            raise Exception(\"file %s is null\" % file)\n        return schema_info\n\n\nif __name__ == \"__main__\":\n    import jsonschema\n\n    # validate_data = {\n    #     \"header\": {\n    #         \"app_id\": \"xxxx\",\n    #         \"uid\": \"xxxxx\"\n    #     },\n    #     \"parameter\": {\n    #         \"chat\": {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/utils/json_schemas/read_json_schemas.py#L153-L189","documentation":"After checking the extension, __call__ verifies the file exists in its configured directory (self.path). If os.path.join(self.path, file) does not exist, a plain Exception is raised reporting the file and directory. Note the typo 'exit' in the message (means 'exist').","triggerScenarios":"Calling the reader with a .json filename that is not present in the directory passed at construction, e.g. reader = ReadJsonSchemas('/app/schemas'); reader('missing.json') when missing.json is not in /app/schemas.","commonSituations":"Wrong directory configured for the reader (deployment packaging left the schema dir out); typo in the schema filename; schema added locally but not committed/deployed; running from a working directory where a relative path resolves differently.","solutions":["Verify the file exists at os.path.join(path, filename) and fix the filename typo if any","Check the directory configured for ReadJsonSchemas points at the folder that actually contains the schema files","Ensure schema files are packaged/deployed with the service (not gitignored or excluded from the image)","Use an absolute, verified path when constructing the reader"],"exampleFix":"// before\nreader = ReadJsonSchemas(\"schemas\")\n// after\nschemas_dir = os.path.join(os.path.dirname(__file__), \"json_schemas\")\nassert os.path.isdir(schemas_dir)\nreader = ReadJsonSchemas(schemas_dir)","handlingStrategy":"validation","validationCode":"import os\npath = os.path.join(schemas_dir, \"my_schema.json\")\nif not os.path.isfile(path):\n    raise FileNotFoundError(f\"schema missing: {path}\")","typeGuard":"def schema_exists(dir_path: str, name: str) -> bool:\n    return os.path.isfile(os.path.join(dir_path, name))","tryCatchPattern":"try:\n    schema = reader(\"my_schema.json\")\nexcept Exception as e:\n    logger.error(\"schema file missing or unreadable: %s\", e)\n    raise","preventionTips":["Verify the schemas directory is included in the deploy artifact/image","Use absolute paths built from __file__ when constructing the reader","List the directory at startup and fail fast on missing expected schemas"],"tags":["python","file","missing-file"],"backgroundTag":"file-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}