{"id":"fbd0ce0d7a147b60","repo":"python-poetry/poetry","slug":"invalid-format-fmt","errorCode":null,"errorMessage":"Invalid format: {fmt}","messagePattern":"Invalid format: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/build.py","lineNumber":43,"sourceCode":"    from cleo.io.io import IO\n\n    from poetry.poetry import Poetry\n    from poetry.utils.env import Env\n\nDistributionType = Literal[\"sdist\", \"wheel\"]\n\n\n@dataclasses.dataclass(frozen=True)\nclass BuildOptions:\n    clean: bool\n    formats: list[DistributionType]\n    output: str\n    config_settings: dict[str, Any] = dataclasses.field(default_factory=dict)\n\n    def __post_init__(self) -> None:\n        for fmt in self.formats:\n            if fmt not in BUILD_FORMATS:\n                raise ValueError(f\"Invalid format: {fmt}\")\n\n\nclass BuildHandler:\n    def __init__(self, poetry: Poetry, env: Env, io: IO) -> None:\n        self.poetry = poetry\n        self.env = env\n        self.io = io\n\n    def _build(\n        self,\n        fmt: DistributionType,\n        executable: Path,\n        target_dir: Path,\n        config_settings: dict[str, Any],\n    ) -> None:\n        builder = BUILD_FORMATS[fmt]\n\n        builder(","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/build.py#L25-L61","documentation":"Raises ValueError in BuildOptions.__post_init__() when a build format string is not one of the keys in BUILD_FORMATS (which by default contains only 'sdist' and 'wheel', extendable by plugins). BuildOptions is constructed from the --format (-f) CLI option; the dataclass validator rejects unknown formats immediately after construction.","triggerScenarios":"Running `poetry build -f tarball` or any format string not in BUILD_FORMATS. The format comes from _prepare_formats() which passes through any non-'all' string verbatim, so any misspelled or unsupported format reaches this check.","commonSituations":"Typo in the format name (e.g. 'sdists', 'wheels'), using a format name from a plugin that isn't installed/enabled, or passing 'all' with extra whitespace.","solutions":["Use 'sdist', 'wheel', or omit -f to build both formats (the default 'all' expands to sdist+wheel).","If using a plugin-provided format, verify the plugin is installed and registered so it extends BUILD_FORMATS."],"exampleFix":"# before (error)\npoetry build -f tar.gz\n# after\npoetry build -f wheel\n# or simply\npoetry build","handlingStrategy":"validation","validationCode":"from poetry.masonry.builders import BUILD_FORMATS\n\ndef validate_format(fmt: str) -> None:\n    if fmt not in BUILD_FORMATS:\n        valid = \", \".join(BUILD_FORMATS)\n        raise ValueError(f\"Invalid format '{fmt}'. Valid: {valid}\")","typeGuard":"from poetry.masonry.builders import BUILD_FORMATS\n\ndef is_valid_format(fmt: str) -> bool:\n    return fmt in BUILD_FORMATS","tryCatchPattern":null,"preventionTips":["Use only 'sdist' or 'wheel' (or omit -f for both).","If using a plugin-provided format, verify the plugin is installed and BUILD_FORMATS includes it.","Avoid typos; the format is case-sensitive and exact."],"tags":["build-command","format","valueerror","build-formats"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}