{"record":{"id":"e3daab9deff4b6c5","repo":"hashicorp/packer","slug":"failed-to-create-sbom-w","errorCode":null,"errorMessage":"failed to create SBOM: %w","messagePattern":"failed to create SBOM: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sbom/generator_syft.go","lineNumber":55,"sourceCode":"\tvar scope source.Scope\n\tswitch g.config.Scope {\n\tcase ScopeAllLayers:\n\t\tscope = source.AllLayersScope\n\tcase \"\", ScopeSquashed:\n\t\tscope = source.SquashedScope\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported scope: %s\", g.config.Scope)\n\t}\n\n\tsbomCfg := syft.DefaultCreateSBOMConfig().\n\t\tWithSearchConfig(cataloging.SearchConfig{\n\t\t\tScope: scope,\n\t\t}).\n\t\tWithParallelism(g.config.Parallelism)\n\n\tsbomResult, err := syft.CreateSBOM(ctx, src, sbomCfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create SBOM: %w\", err)\n\t}\n\n\treturn g.encodeToFormat(sbomResult)\n}\n\n// encodeToFormat encodes the SBOM to the requested format.\nfunc (g *Generator) encodeToFormat(sbomData *sbom.SBOM) ([]byte, error) {\n\tswitch g.config.Format {\n\tcase FormatCycloneDX:\n\t\tcfg := cyclonedxjson.DefaultEncoderConfig()\n\t\tcfg.Pretty = true\n\t\tencoder, err := cyclonedxjson.NewFormatEncoderWithConfig(\n\t\t\tcfg,\n\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)","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/sbom/generator_syft.go#L37-L73","documentation":"syft.CreateSBOM catalogs the resolved source and failed — wrapped as `failed to create SBOM: %w`. This covers cataloger errors during package discovery: unreadable files inside the scan scope, database/cataloger initialization issues (note the modernc.org/sqlite import), context cancellation, or internal Syft panics surfaced as errors.","triggerScenarios":"Context cancelled/timed out mid-catalog; permission errors reading files under the scan path; corrupted image layers; cataloger config (parallelism, exclusions) triggering failures; sqlite driver initialization problems in constrained environments.","commonSituations":"Long scans hitting build timeouts; scanning filesystems with unreadable mounted secrets; very low memory environments; unusual filesystems inside the image that trip specific catalogers.","solutions":["Inspect the wrapped cause from %w to identify the failing cataloger or file","Increase build/step timeouts and check context cancellation","Increase Parallelism or set exclusions (Config.Exclude) to skip problematic paths","Ensure the process has read access to everything under the scan scope","Retry after checking Syft version compatibility if a cataloger bug is implicated"],"exampleFix":"// before\ngen := sbom.NewGenerator(sbom.Config{ScanPath: \"/\"})\nout, err := gen.Generate(ctx) // cancelled by short step timeout\n// after\nctx, cancel := context.WithTimeout(ctx, 30*time.Minute)\ndefer cancel()\ngen := sbom.NewGenerator(sbom.Config{ScanPath: \"/\", Exclude: []string{\"/proc\", \"/sys\"}})\nout, err := gen.Generate(ctx)","handlingStrategy":"try-catch","validationCode":"ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)\ndefer cancel()\n// ensure scan path readable\n_ = filepath.Walk(cfg.ScanPath, func(p string, i os.FileInfo, e error) error { return e })","typeGuard":null,"tryCatchPattern":"out, err := gen.Generate(ctx)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { return retryWithLongerTimeout() }\n    return fmt.Errorf(\"SBOM cataloging failed: %w\", err)\n}","preventionTips":["Allocate generous timeouts for full-filesystem scans","Exclude /proc, /sys and other pseudo-filesystems via Config.Exclude","Ensure read permissions across the scan scope","Monitor memory when using high Parallelism"],"tags":["go","syft","cataloging","timeout","sbom"],"backgroundTag":"sbom-generation-failed","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"}