{"record":{"id":"07bc01a311ebbe1a","repo":"YunaiV/yudao-cloud","slug":"args-type","errorCode":null,"errorMessage":"不支持目标数据库类型: {args.type}","messagePattern":"不支持目标数据库类型: (.+?)","errorType":"console","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","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/yudao-cloud/blob/477be9dd49ab7223a972a6abdff0684d6423dec3/sql/tools/convertor.py#L1051-L1076","documentation":"Raised at the end of the convertor-selection if/elif chain in sql/tools/convertor.py's main(): the --type CLI argument is compared against the supported target databases (oracle, sqlserver, dm8, kingbase, opengauss, highgo, plus the branches above them such as postgresql/mysql-family); any other value falls to `else: raise NotImplementedError(f\"不支持目标数据库类型: {args.type}\")`. It means the CLI was invoked with an unrecognized --type value.","triggerScenarios":"Running `python convertor.py <sql_file> --type X` where X is not one of the supported literals — e.g. a typo ('postgre', 'opengause'), wrong casing if the comparison is case-sensitive ('DM8' vs 'dm8'), or a genuinely unsupported target ('sqlite'). The error occurs before any convertor is constructed, so no output is produced.","commonSituations":"Shell scripts or CI pipelines with a hardcoded --type that drifts from the tool's supported list after a version change; copy-pasting the command from docs for a different fork; trailing whitespace in the argument; new team member guessing the type name.","solutions":["Re-run with the exact supported literal: check argparse's choices / the elif chain (oracle, sqlserver, dm8, kingbase, opengauss, highgo, and the branches above — grep `args.type ==` in convertor.py) and use one of those strings verbatim.","If the argument comes from a script/env var, echo it first to catch typos, casing, or trailing whitespace.","Add `choices=[...]` to the argparse --type argument so argparse itself rejects invalid values with a usage message instead of a stack trace.","To support a new target database, write a new Convertor subclass and add an elif branch (or a registry dict) instead of bypassing the check."],"exampleFix":"# before\nparser.add_argument(\"--type\", required=True)  # any string accepted, bad value raises NotImplementedError later\n\n# after — argparse validates the value up front\nparser.add_argument(\n    \"--type\",\n    required=True,\n    choices=[\"postgresql\", \"oracle\", \"sqlserver\", \"dm8\", \"kingbase\", \"opengauss\", \"highgo\"],\n)","handlingStrategy":"validation","validationCode":"import subprocess, sys\n\nSUPPORTED = {\"postgresql\", \"oracle\", \"sqlserver\", \"dm8\", \"kingbase\", \"opengauss\", \"highgo\"}\ntarget = args.type.strip().lower()   # normalize before spawning\nif target not in SUPPORTED:\n    sys.exit(f\"--type must be one of {sorted(SUPPORTED)}, got {target!r}\")\nsubprocess.run([sys.executable, \"sql/tools/convertor.py\", sql_file, \"--type\", target], check=True)","typeGuard":"SUPPORTED_TYPES = (\"postgresql\", \"oracle\", \"sqlserver\", \"dm8\", \"kingbase\", \"opengauss\", \"highgo\")\n\ndef is_supported_db_type(t: str) -> bool:\n    \"\"\"True if the convertor CLI accepts --type t (case-sensitive, exact match).\"\"\"\n    return t in SUPPORTED_TYPES","tryCatchPattern":"try:\n    main()  # or subprocess.run of the CLI\nexcept NotImplementedError as e:\n    # e.args[0] is like: 不支持目标数据库类型: postgre\n    # fix: pass one of the exact literals from the elif chain (grep 'args.type ==' in convertor.py)\n    print(f\"unsupported --type; supported values are listed in convertor.py's elif chain\", file=sys.stderr)\n    sys.exit(2)","preventionTips":["Grep `args.type ==` in convertor.py (or check argparse choices) once and pin the supported list in your scripts/docs.","Pass --type via a shell variable sourced from one config file, not repeated literals across scripts.","Add choices=[...] to argparse so bad values fail fast with a usage message.","In CI, assert the requested target is in the supported set before invoking the convertor step."],"tags":["sql","cli","argparse","configuration","not-implemented","python"],"backgroundTag":null,"analyzedSha":"477be9dd49ab7223a972a6abdff0684d6423dec3","analyzedAt":"2026-08-14T13:35:31.121Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}