YunaiV/yudao-cloud · error · NotImplementedError
不支持目标数据库类型: {args.type}
Error message
不支持目标数据库类型: {args.type} What it means
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.
Source
Thrown at sql/tools/convertor.py:1069
sql_file = pathlib.Path(args.path).resolve().as_posix()
convertor = None
if args.type == "postgres":
convertor = PostgreSQLConvertor(sql_file)
elif args.type == "oracle":
convertor = OracleConvertor(sql_file)
elif args.type == "sqlserver":
convertor = SQLServerConvertor(sql_file)
elif args.type == "dm8":
convertor = DM8Convertor(sql_file)
elif args.type == "kingbase":
convertor = KingbaseConvertor(sql_file)
elif args.type == "opengauss":
convertor = OpengaussConvertor(sql_file)
elif args.type == "highgo":
convertor = HighGoConvertor(sql_file)
else:
raise NotImplementedError(f"不支持目标数据库类型: {args.type}")
convertor.print()
if __name__ == "__main__":
main()
View on GitHub (pinned to 477be9dd49)
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.
Example fix
# before
parser.add_argument("--type", required=True) # any string accepted, bad value raises NotImplementedError later
# after — argparse validates the value up front
parser.add_argument(
"--type",
required=True,
choices=["postgresql", "oracle", "sqlserver", "dm8", "kingbase", "opengauss", "highgo"],
) Defensive patterns
Strategy: validation
Validate before calling
import subprocess, sys
SUPPORTED = {"postgresql", "oracle", "sqlserver", "dm8", "kingbase", "opengauss", "highgo"}
target = args.type.strip().lower() # normalize before spawning
if target not in SUPPORTED:
sys.exit(f"--type must be one of {sorted(SUPPORTED)}, got {target!r}")
subprocess.run([sys.executable, "sql/tools/convertor.py", sql_file, "--type", target], check=True) Type guard
SUPPORTED_TYPES = ("postgresql", "oracle", "sqlserver", "dm8", "kingbase", "opengauss", "highgo")
def is_supported_db_type(t: str) -> bool:
"""True if the convertor CLI accepts --type t (case-sensitive, exact match)."""
return t in SUPPORTED_TYPES Try / catch
try:
main() # or subprocess.run of the CLI
except NotImplementedError as e:
# e.args[0] is like: 不支持目标数据库类型: postgre
# fix: pass one of the exact literals from the elif chain (grep 'args.type ==' in convertor.py)
print(f"unsupported --type; supported values are listed in convertor.py's elif chain", file=sys.stderr)
sys.exit(2) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- f"未支持的类型: '{col['type']}' (列: {name}, 表: {ddl['table_name']}
- couldn't lookup datasource from {}: {}
- DataSource or JDBC properties have to be specified in a proc
- couldn't deduct database type from database product name '{}
- Exception while initializing Database connection
AI-assisted analysis of YunaiV/yudao-cloud@477be9dd49 (2026-08-14).
Data as JSON: /api/errors/07bc01a311ebbe1a.
Report an issue: GitHub.