{"record":{"id":"9a9a42e11f69c076","repo":"iflytek/astron-agent","slug":"file-s-suffix-not-json","errorCode":null,"errorMessage":"file %s suffix not .json","messagePattern":"file (.+?) suffix not \\.json","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/plugin/link/utils/json_schemas/read_json_schemas.py","lineNumber":168,"sourceCode":"\n    This class handles the reading and processing of JSON schema files\n    from a specified directory path.\n    \"\"\"\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\"","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/utils/json_schemas/read_json_schemas.py#L150-L186","documentation":"ReadJsonSchemas.__call__ reads a JSON schema file from a fixed directory and returns its raw text. Before reading it enforces that the requested file has a '.json' extension; if it does not, a plain Exception is raised. This guards against accidentally passing schema names, IDs, or paths without the extension.","triggerScenarios":"Calling the reader instance with a file argument that does not end with '.json', e.g. reader('my_schema') or reader('schema.txt') or a path with an extension like 'dir/schema.yaml'.","commonSituations":"Passing a schema identifier from a config or DB instead of the actual filename; forgetting the extension; concatenating a directory that already contains the extension so the name has a doubled or missing suffix.","solutions":["Append the '.json' extension to the file argument before calling the reader","If the value is an ID/name, resolve it to the actual schema filename ending in .json first","Strip any directory portion and pass only the bare filename as expected by the reader"],"exampleFix":"// before\nschema = reader(\"user_schema\")\n// after\nname = \"user_schema\" if name.endswith(\".json\") else name + \".json\"\nschema = reader(\"user_schema.json\")","handlingStrategy":"validation","validationCode":"def ensure_json_filename(name: str) -> str:\n    if not name.endswith(\".json\"):\n        raise ValueError(f\"expected a .json schema filename, got: {name}\")\n    return name","typeGuard":"def is_json_filename(name: object) -> bool:\n    return isinstance(name, str) and name.endswith(\".json\")","tryCatchPattern":null,"preventionTips":["Always pass bare filenames with the .json extension to the reader","Store schema names in config with the extension included","Add a unit test asserting the reader raises on non-.json input"],"tags":["python","file","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}