{"record":{"id":"deba60ba722f8323","repo":"hashicorp/terraform","slug":"invalid-format-for-s-w","errorCode":null,"errorMessage":"Invalid format for %s: %w","messagePattern":"Invalid format for (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/reattach/reattach.go","lineNumber":54,"sourceCode":"//\n// Calling code is expected to pass in the value of os.Getenv(\"TF_REATTACH_PROVIDERS\")\nfunc ParseReattachProviders(in string) (map[addrs.Provider]*plugin.ReattachConfig, error) {\n\tunmanagedProviders := map[addrs.Provider]*plugin.ReattachConfig{}\n\tif in != \"\" {\n\t\ttype reattachConfig struct {\n\t\t\tProtocol        string\n\t\t\tProtocolVersion int\n\t\t\tAddr            struct {\n\t\t\t\tNetwork string\n\t\t\t\tString  string\n\t\t\t}\n\t\t\tPid  int\n\t\t\tTest bool\n\t\t}\n\t\tvar m map[string]reattachConfig\n\t\terr := json.Unmarshal([]byte(in), &m)\n\t\tif err != nil {\n\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid format for %s: %w\", TF_REATTACH_PROVIDERS, err)\n\t\t}\n\t\tfor p, c := range m {\n\t\t\ta, diags := addrs.ParseProviderSourceString(p)\n\t\t\tif diags.HasErrors() {\n\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Error parsing %q as a provider address: %w\", a, diags.Err())\n\t\t\t}\n\t\t\tvar addr net.Addr\n\t\t\tswitch c.Addr.Network {\n\t\t\tcase \"unix\":\n\t\t\t\taddr, err = net.ResolveUnixAddr(\"unix\", c.Addr.String)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid unix socket path %q for %q: %w\", c.Addr.String, p, err)\n\t\t\t\t}\n\t\t\tcase \"tcp\":\n\t\t\t\taddr, err = net.ResolveTCPAddr(\"tcp\", c.Addr.String)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid TCP address %q for %q: %w\", c.Addr.String, p, err)\n\t\t\t\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/getproviders/reattach/reattach.go#L36-L72","documentation":"From ParseReattachProviders. The TF_REATTACH_PROVIDERS environment variable must be a JSON object mapping provider source strings to reattach config objects. json.Unmarshal failing on the raw bytes produces this error, with the underlying JSON error wrapped via %w. Any JSON syntax problem - stray comma, missing brace, wrong types - surfaces here.","triggerScenarios":"ParseReattachProviders(os.Getenv(\"TF_REATTACH_PROVIDERS\")) is called (directly or via IsProviderReattached); the env var is non-empty but json.Unmarshal at line 52 returns an error. Common when the JSON was hand-written, generated by a buggy dev tool, or pasted with smart quotes / trailing commas.","commonSituations":"Developers using TF_REATTACH_PROVIDERS to debug a provider under development with a malformed JSON blob. Copy-paste from docs introduced smart quotes or missing brackets. A shell quoting bug truncated/escaped the value. An extra trailing comma or a comment (JSON has none).","solutions":["Validate the env var's value with a JSON linter (e.g. `echo \"$TF_REATTACH_PROVIDERS\" | jq .`) before running Terraform.","Ensure the value is a JSON object whose values match the ReattachConfig shape (Protocol, ProtocolVersion, Addr.Network, Addr.String, Pid, Test).","Fix shell quoting so the whole JSON string is passed intact (single-quote the assignment).","Remove the env var if reattach is not actually needed: unset TF_REATTACH_PROVIDERS."],"exampleFix":"// before (shell)\nexport TF_REATTACH_PROVIDERS='{\"foobar\": {\"Protocol\":\"grpc\",\"ProtocolVersion\":6,\"Pid\":12345,\"Test\":true,\"Addr\":{\"Network\":\"unix\",\"String\":\"/tmp/plugin\"},}}'  // trailing comma -> JSON error\n// after\nexport TF_REATTACH_PROVIDERS='{\"foobar\":{\"Protocol\":\"grpc\",\"ProtocolVersion\":6,\"Pid\":12345,\"Test\":true,\"Addr\":{\"Network\":\"unix\",\"String\":\"/tmp/plugin\"}}}'","handlingStrategy":"validation","validationCode":"// Validate the env var JSON before passing it to Terraform.\nfunc validateReattachJSON(in string) error {\n    if in == \"\" { return nil }\n    var m map[string]json.RawMessage\n    return json.Unmarshal([]byte(in), &m)\n}\nif err := validateReattachJSON(os.Getenv(reattach.TF_REATTACH_PROVIDERS)); err != nil {\n    return fmt.Errorf(\"TF_REATTACH_PROVIDERS is not valid JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Wrap with the env var name so the user knows which input is broken.\nproviders, err := reattach.ParseReattachProviders(os.Getenv(\"TF_REATTACH_PROVIDERS\"))\nif err != nil {\n    return fmt.Errorf(\"cannot start: %w\", err)\n}","preventionTips":["Single-quote the env var assignment in shell to preserve the whole JSON string.","Generate TF_REATTACH_PROVIDERS with a JSON encoder, never by hand or string concatenation.","Lint the value with `jq .` before running Terraform."],"tags":["config","json","env-var","reattach","developer-debug"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}