hashicorp/packer · error

unsupported scope: %s (supported: squashed, all-layers)

Error message

unsupported scope: %s (supported: squashed, all-layers)

What it means

ParseScopeFromArgs accepts only 'squashed', 'all-layers', plus aliases 'all' and 'alllayers' (after lowercasing/trimming). Anything else returns `unsupported scope: %s (supported: squashed, all-layers)`. Scope controls whether Syft catalogs the merged image filesystem or every layer.

Source

Thrown at internal/sbom/generator.go:75

		return FormatCycloneDX, nil
	}
	if strings.Contains(formatArg, "spdx") {
		return FormatSPDX, nil
	}

	return "", fmt.Errorf("unsupported format: %s", formatArg)
}

func ParseScopeFromArgs(scopeArg string) (string, error) {
	scopeArg = strings.ToLower(strings.TrimSpace(scopeArg))

	switch scopeArg {
	case ScopeSquashed:
		return ScopeSquashed, nil
	case ScopeAllLayers, "all", "alllayers":
		return ScopeAllLayers, nil
	default:
		return "", fmt.Errorf("unsupported scope: %s (supported: squashed, all-layers)", scopeArg)
	}
}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Pass exactly "squashed" or "all-layers" (aliases "all" and "alllayers" also work)
  2. Rely on the empty-string default: NewGenerator sets ScopeSquashed when Scope is empty
  3. Read the error's supported list and correct the spelling/hyphenation
  4. Validate scope at config-parse time rather than at generate time

Example fix

// before
scope, err := sbom.ParseScopeFromArgs("all layers")
// after
scope, err := sbom.ParseScopeFromArgs("all-layers")
Defensive patterns

Strategy: validation

Validate before calling

scope, err := sbom.ParseScopeFromArgs(scopeArg)
if err != nil {
    return fmt.Errorf("invalid SBOM scope %q: %w", scopeArg, err)
}

Type guard

func isSupportedScope(s string) bool {
    switch strings.ToLower(strings.TrimSpace(s)) {
    case "squashed", "all-layers", "all", "alllayers", "": return true
    }
    return false
}

Try / catch

scope, err := sbom.ParseScopeFromArgs(arg)
if err != nil {
    return fmt.Errorf("scope must be squashed or all-layers: %w", err)
}

Prevention

When it happens

Trigger: Calling ParseScopeFromArgs("all layers"), ("squashed-layers"), ("directory"), or empty-but-set odd values like "squashed " trimmed fine, but "SquashedLayers" fails.

Common situations: Copying scope flags from other tools (trivy/grype use different names); typos like "all-layerss"; expecting syft's multi-value scope syntax; blank config strings from env vars that bypass NewGenerator defaults.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/78559b4fb4326a6b. Report an issue: GitHub.