{"record":{"id":"c35716c6cb8619ce","repo":"YunaiV/ruoyi-vue-pro","slug":"args-type","errorCode":null,"errorMessage":"不支持目标数据库类型: {args.type}","messagePattern":"不支持目标数据库类型: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"warning","filePath":"sql/tools/convertor.py","lineNumber":1069,"sourceCode":"\n    sql_file = pathlib.Path(args.path).resolve().as_posix()\n    convertor = None\n    if args.type == \"postgres\":\n        convertor = PostgreSQLConvertor(sql_file)\n    elif args.type == \"oracle\":\n        convertor = OracleConvertor(sql_file)\n    elif args.type == \"sqlserver\":\n        convertor = SQLServerConvertor(sql_file)\n    elif args.type == \"dm8\":\n        convertor = DM8Convertor(sql_file)\n    elif args.type == \"kingbase\":\n        convertor = KingbaseConvertor(sql_file)\n    elif args.type == \"opengauss\":\n        convertor = OpengaussConvertor(sql_file)\n    elif args.type == \"highgo\":\n        convertor = HighGoConvertor(sql_file)\n    else:\n        raise NotImplementedError(f\"不支持目标数据库类型: {args.type}\")\n\n    convertor.print()\n\n\nif __name__ == \"__main__\":\n    main()\n","sourceCodeStart":1051,"sourceCodeEnd":1076,"githubUrl":"https://github.com/YunaiV/ruoyi-vue-pro/blob/0418084e222612af2fc1141f566af454f9236ab1/sql/tools/convertor.py#L1051-L1076","documentation":"Raised by main() when argparse's args.type matches none of the if/elif branches mapping to a convertor class (postgres, oracle, sqlserver, dm8, kingbase, opengauss, highgo). In practice this is dead code under normal CLI use: the parser declares the same seven strings in its choices=[...] argument, so argparse exits with its own 'invalid choice' error (exit code 2) before main() ever reaches the else. The NotImplementedError only fires if the choices list and the elif chain drift out of sync, or if main() is invoked programmatically with an unguarded type.","triggerScenarios":"Calling the script with a type not in {postgres, oracle, sqlserver, dm8, kingbase, opengauss, highgo} while bypassing argparse (e.g. importing main and calling it directly), OR after someone widens choices without adding the matching elif branch. Standard `python convertor.py <badtype>` never reaches here — argparse rejects it first.","commonSituations":"A maintainer adds a new dialect to choices but forgets the elif; a downstream script imports main() and passes args programmatically; refactoring that desynchronizes the choices list and the dispatch chain.","solutions":["Add the missing elif branch instantiating the new convertor class, mirroring the existing pattern.","Keep argparse choices=[...] and the if/elif dispatch generated from a single source (e.g. a dict mapping type→convertor class) so they cannot drift.","If invoking programmatically, validate the type against the known set before calling main().","Use `python convertor.py -h` to list the supported types when unsure."],"exampleFix":"# before\nif args.type == \"postgres\":\n    convertor = PostgreSQLConvertor(sql_file)\nelif args.type == \"oracle\":\n    ...\nelse:\n    raise NotImplementedError(f\"不支持目标数据库类型: {args.type}\")\n\n# after — single source of truth\nCONVERTORS = {\n    \"postgres\": PostgreSQLConvertor,\n    \"oracle\": OracleConvertor,\n    \"sqlserver\": SQLServerConvertor,\n    \"dm8\": DM8Convertor,\n    \"kingbase\": KingbaseConvertor,\n    \"opengauss\": OpengaussConvertor,\n    \"highgo\": HighgoConvertor,\n}\nparser.add_argument(\"type\", choices=list(CONVERTORS))  # argparse + dispatch share one map\n...\nconvertor = CONVERTORS[args.type](sql_file)","handlingStrategy":"validation","validationCode":"# argparse already validates via choices=[...]; mirror it if calling main() directly\nSUPPORTED_TYPES = {\"postgres\", \"oracle\", \"sqlserver\", \"dm8\", \"kingbase\", \"opengauss\", \"highgo\"}\nif args.type not in SUPPORTED_TYPES:\n    raise SystemExit(f\"unsupported type {args.type!r}; choose from {sorted(SUPPORTED_TYPES)}\")","typeGuard":"from typing import Literal\nDBType = Literal[\"postgres\", \"oracle\", \"sqlserver\", \"dm8\", \"kingbase\", \"opengauss\", \"highgo\"]","tryCatchPattern":null,"preventionTips":["Drive argparse choices and the dispatch chain from one dict so they cannot drift.","Run `python convertor.py -h` to see the authoritative supported-type list.","When importing main() programmatically, validate the type against the known set first.","On adding a new dialect, update choices, the elif branch, and the Literal alias together."],"tags":["sql","convertor","cli","argparse","dispatch"],"backgroundTag":null,"analyzedSha":"0418084e222612af2fc1141f566af454f9236ab1","analyzedAt":"2026-08-14T00:56:18.412Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}