{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/reattach/reattach.go#L36-L72","documentation":"Thrown by the reattach config loader when the TF_REATTACH_PROVIDERS environment variable cannot be unmarshalled into a map[string]reattachConfig. The value must be valid JSON keyed by provider source string.","triggerScenarios":"json.Unmarshal([]byte(in), &m) returned a non-nil error while parsing the TF_REATTACH_PROVIDERS value.","commonSituations":"TF_REATTACH_PROVIDERS set to malformed JSON (trailing comma, single quotes, unquoted keys); value copy-pasted from a log with truncation; shell quoting that broke the JSON; missing closing brace.","solutions":["Validate the TF_REATTACH_PROVIDERS JSON with a linter before exporting it","Re-emit the value from the test helper / debug command that produced it","Ensure shell quoting preserves the literal JSON (single-quote the whole value in sh)"],"exampleFix":"# before\nexport TF_REATTACH_PROVIDERS='{\"registry.terraform.io/hashicorp/null\": {\"protocol\":\"grpc\",\"protocol_version\":5,\"addr\":{\"network\":\"unix\",\"string\":\"/tmp/null\"}}}'\n\n# ensure balanced braces and double quotes; re-export and retry","handlingStrategy":"validation","validationCode":"// Validate the env var parses as JSON before passing it to the loader.\nvar probe map[string]json.RawMessage\nif err := json.Unmarshal([]byte(raw), &probe); err != nil {\n    return fmt.Errorf(\"TF_REATTACH_PROVIDERS is not valid JSON: %w\", err)\n}","typeGuard":"func IsReattachJSON(s string) bool {\n    var m map[string]json.RawMessage\n    return json.Unmarshal([]byte(s), &m) == nil\n}","tryCatchPattern":"providers, err := reattach.DecodeProviders(raw)\nif err != nil {\n    return fmt.Errorf(\"invalid TF_REATTACH_PROVIDERS: %w\", err)\n}","preventionTips":["Generate TF_REATTACH_PROVIDERS from a debug/test helper rather than hand-editing","Shell-quote the entire JSON value with single quotes to preserve double quotes","Lint the JSON before exporting it"],"tags":["reattach","json","env-var","config","validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}