{"record":{"id":"f5c4a2e42707e5e2","repo":"hashicorp/packer","slug":"unsupported-format-s-supported-cyclonedx-spdx","errorCode":null,"errorMessage":"unsupported format: %s (supported: cyclonedx, spdx)","messagePattern":"unsupported format: (.+?) \\(supported: cyclonedx, spdx\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sbom/generator_syft.go","lineNumber":87,"sourceCode":"\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create CycloneDX encoder: %w\", err)\n\t\t}\n\t\treturn format.Encode(*sbomData, encoder)\n\n\tcase FormatSPDX:\n\t\tcfg := spdxjson.DefaultEncoderConfig()\n\t\tcfg.Pretty = true\n\t\tencoder, err := spdxjson.NewFormatEncoderWithConfig(\n\t\t\tcfg,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create SPDX encoder: %w\", err)\n\t\t}\n\t\treturn format.Encode(*sbomData, encoder)\n\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported format: %s (supported: cyclonedx, spdx)\", g.config.Format)\n\t}\n}\n","sourceCodeStart":69,"sourceCodeEnd":90,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/sbom/generator_syft.go#L69-L90","documentation":"encodeToFormat switches on g.config.Format and only supports \"cyclonedx\" and \"spdx\". Any other value falls into the default branch and returns \"unsupported format: %s (supported: cyclonedx, spdx)\". It is a straightforward configuration validation error naming the valid alternatives.","triggerScenarios":"Setting the generator's Format config to any string other than \"cyclonedx\" or \"spdx\" (e.g. \"json\", \"cyclonedx-json\", \"SPDX\", or a typo) before calling Generate — the switch is case-sensitive and exact-match.","commonSituations":"Typos or wrong casing in a Packer template/plugin config field; users copying syft CLI format names (\"syft-json\", \"spdx-json\") which differ from the accepted constants; leaving an empty string when the code does not default it.","solutions":["Set config.Format to exactly \"cyclonedx\" or \"spdx\" (lowercase)","Trim and lowercase user-supplied format values before constructing the Generator config","Add an upfront validation in the config Prepare step to reject invalid formats with a friendly message","If you need another syft format (e.g. spdx-tag-value), extend encodeToFormat with a new case and constant"],"exampleFix":"// before\nformat := cfg[\"format\"] // \"SPDX-JSON\"\ng, _ := NewGenerator(Config{Format: format})\n// after\nformat := strings.ToLower(strings.TrimSpace(cfg[\"format\"]))\nif format != FormatCycloneDX && format != FormatSPDX {\n    return fmt.Errorf(\"invalid sbom format %q; must be cyclonedx or spdx\", format)\n}\ng, _ := NewGenerator(Config{Format: format})","handlingStrategy":"validation","validationCode":"func validateFormat(f string) error {\n    if f != \"cyclonedx\" && f != \"spdx\" {\n        return fmt.Errorf(\"format %q must be exactly \\\"cyclonedx\\\" or \\\"spdx\\\"\", f)\n    }\n    return nil\n}","typeGuard":"func isSupportedFormat(f string) bool {\n    return f == FormatCycloneDX || f == FormatSPDX\n}","tryCatchPattern":"out, err := gen.Generate(ctx)\nif err != nil {\n    var unsupportedErr = \"unsupported format\"\n    if strings.Contains(err.Error(), unsupportedErr) {\n        return fmt.Errorf(\"bad sbom format config; use cyclonedx or spdx: %w\", err)\n    }\n    return err\n}","preventionTips":["Normalize (trim+lowercase) any user-supplied format string before constructing the config","Define the format value only via the exported constants FormatCycloneDX/FormatSPDX, never raw strings","Validate the format in the component's Prepare/config stage so it fails fast at parse time"],"tags":["sbom","config","validation","format"],"backgroundTag":"unsupported-format-value","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}