{"record":{"id":"a1755848e91c65f0","repo":"hashicorp/packer","slug":"d-is-an-invalid-trace-level-for-debug-mode-val","errorCode":null,"errorMessage":"%d is an invalid Trace level for `debug_mode`; valid values are 0, 1, and 2","messagePattern":"(.+?) is an invalid Trace level for `debug_mode`; valid values are 0, 1, and 2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/powershell/provisioner.go","lineNumber":291,"sourceCode":"\n\t// Do a check for bad environment variables, such as '=foo', 'foobar'\n\tfor _, kv := range p.config.Vars {\n\t\tvs := strings.SplitN(kv, \"=\", 2)\n\t\tif len(vs) != 2 || vs[0] == \"\" {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Environment variable not in format 'key=value': %s\", kv))\n\t\t}\n\t}\n\n\tif p.config.ExecutionPolicy > 7 {\n\t\terrs = packersdk.MultiErrorAppend(errs, fmt.Errorf(`Invalid execution `+\n\t\t\t`policy provided. Please supply one of: \"bypass\", \"allsigned\",`+\n\t\t\t` \"default\", \"remotesigned\", \"restricted\", \"undefined\", `+\n\t\t\t`\"unrestricted\", \"none\".`))\n\t}\n\n\tif !(p.config.DebugMode >= 0 && p.config.DebugMode <= 2) {\n\t\terrs = packersdk.MultiErrorAppend(errs, fmt.Errorf(\"%d is an invalid Trace level for `debug_mode`; valid values are 0, 1, and 2\", p.config.DebugMode))\n\t}\n\n\tif errs != nil {\n\t\treturn errs\n\t}\n\n\treturn nil\n}\n\n// Takes the inline scripts, adds a wrapper around the inline scripts, concatenates them into a temporary file and\n// returns a string containing the location of said file.\nfunc extractInlineScript(p *Provisioner) (string, error) {\n\ttemp, err := tmp.File(\"powershell-provisioner\")\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tdefer temp.Close()","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/powershell/provisioner.go#L273-L309","documentation":"Validation guard in the PowerShell provisioner's Prepare. debug_mode maps to the Windows Trace-Command verbosity level, which only accepts 0 (off), 1, or 2; this error fires when debug_mode is set to any other integer. Change debug_mode in the provisioner block to 0, 1, or 2.","triggerScenarios":"Prepare called with config.DebugMode < 0 or > 2, e.g. debug_mode = 3 or a negative number in the template.","commonSituations":"Copy-pasting a debug level from another provisioner that allows more levels; thinking higher numbers mean more verbose output and escalating past 2; typing a typo like 22.","solutions":["Set debug_mode's trace level to 0, 1, or 2","Remove debug_mode if you don't need PowerShell transcript/tracing output"],"exampleFix":"// before\ndebug_mode = 3\n// after\ndebug_mode = 2","handlingStrategy":"validation","validationCode":"// Go, before Prepare\nif cfg.DebugMode < 0 || cfg.DebugMode > 2 {\n    return fmt.Errorf(\"debug_mode must be 0, 1 or 2, got %d\", cfg.DebugMode)\n}","typeGuard":null,"tryCatchPattern":"// Go\nif err := prov.Prepare(cfg); err != nil {\n    if strings.Contains(err.Error(), \"invalid Trace level\") {\n        cfg.DebugMode = 0\n    }\n    return err\n}","preventionTips":["Only use 0, 1, or 2 for debug_mode — 2 is maximum verbosity.","Remove debug_mode from production templates; keep it only in local dev overrides.","Use an HCL variable validation block to constrain the range in shared templates."],"tags":["powershell","provisioner","debug-mode","configuration"],"backgroundTag":"invalid-enum-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"}