{"record":{"id":"c909e77ea0783f68","repo":"hashicorp/packer","slug":"failed-to-get-source-w","errorCode":null,"errorMessage":"failed to get source: %w","messagePattern":"failed to get source: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sbom/generator_syft.go","lineNumber":33,"sourceCode":"\t\"github.com/anchore/syft/syft/cataloging\"\n\t\"github.com/anchore/syft/syft/format\"\n\t\"github.com/anchore/syft/syft/format/cyclonedxjson\"\n\t\"github.com/anchore/syft/syft/format/spdxjson\"\n\t\"github.com/anchore/syft/syft/sbom\"\n\t\"github.com/anchore/syft/syft/source\"\n)\n\n// Generate creates an SBOM for the configured scan path and returns the encoded result.\nfunc (g *Generator) Generate(ctx context.Context) ([]byte, error) {\n\tsourceInput := g.config.ScanPath\n\tgetSourceCfg := syft.DefaultGetSourceConfig()\n\tif len(g.config.Exclude) > 0 {\n\t\tgetSourceCfg = getSourceCfg.WithExcludeConfig(source.ExcludeConfig{Paths: g.config.Exclude})\n\t}\n\n\tsrc, err := syft.GetSource(ctx, sourceInput, getSourceCfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get source: %w\", err)\n\t}\n\tdefer func() { _ = src.Close() }()\n\n\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)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/sbom/generator_syft.go#L15-L51","documentation":"Generator.Generate calls syft.GetSource to resolve the configured ScanPath into a catalogable source (directory, container image, etc.). Any failure resolving that source — path does not exist, unsupported scheme, registry auth failure, image pull error — is wrapped as `failed to get source: %w`. The wrapped Syft error carries the real cause.","triggerScenarios":"ScanPath points to a nonexistent directory; ScanPath uses a scheme Syft cannot handle; scanning registry/image references without credentials or network; image reference malformed; platform/daemon unavailable for docker:// sources.","commonSituations":"Wrong scan path in config (typo or path not mounted in build VM); scanning a private image without registry credentials; air-gapped environment trying to pull a remote image; Syft version change altering supported source schemes.","solutions":["Read the inner error from %w — it names the actual source failure","Verify the ScanPath exists and is accessible from the process (ls/stat it)","For image sources, run docker pull / crane auth manually to validate access","Check registry credentials and network/proxy configuration","Ensure the source scheme is supported by the embedded Syft version"],"exampleFix":"// before\nCfg.ScanPath = \"/opt/app\" // not present inside build VM\n// after\nif _, err := os.Stat(cfg.ScanPath); err != nil {\n    return fmt.Errorf(\"scan path unavailable: %w\", err)\n}\n// or use a scheme Syft supports, e.g. \"docker:image:tag\" or an absolute dir","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(cfg.ScanPath); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"scan path %q is not an accessible directory\", cfg.ScanPath)\n}","typeGuard":null,"tryCatchPattern":"out, err := gen.Generate(ctx)\nif err != nil {\n    var inner error = errors.Unwrap(err)\n    return fmt.Errorf(\"SBOM source error (check path/registry auth): %w\", err)\n}","preventionTips":["Stat the scan path inside the environment where Generate runs","Pre-authenticate registry access before scanning image sources","Keep source schemes simple (local directory) inside build VMs","Check network/proxy settings for remote image scans"],"tags":["go","syft","network","filesystem","sbom"],"backgroundTag":"source-resolution-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"}