{"record":{"id":"c39212d1bff2cb8b","repo":"hashicorp/packer","slug":"invalidclientconfig","errorCode":"InvalidClientConfig","errorMessage":"Failed to check for HCP auth, error: %s","messagePattern":"Failed to check for HCP auth, error: (.+?)","errorType":"error_code","errorClass":"ClientError","httpStatus":null,"severity":"error","filePath":"internal/hcp/api/client.go","lineNumber":43,"sourceCode":"\tPacker       packerSvc.ClientService\n\tOrganization organizationSvc.ClientService\n\tProject      projectSvc.ClientService\n\n\t// OrganizationID  is the organization unique identifier on HCP.\n\tOrganizationID string\n\n\t// ProjectID  is the project unique identifier on HCP.\n\tProjectID string\n}\n\n// NewClient returns an authenticated client to a HCP Packer Registry.\n// Upon error a HCPClientError will be returned.\nfunc NewClient() (*Client, error) {\n\thasAuth, err := env.HasHCPAuth()\n\tif err != nil {\n\t\treturn nil, &ClientError{\n\t\t\tStatusCode: InvalidClientConfig,\n\t\t\tErr:        fmt.Errorf(\"Failed to check for HCP auth, error: %s\", err.Error()),\n\t\t}\n\t}\n\tif !hasAuth {\n\t\treturn nil, &ClientError{\n\t\t\tStatusCode: InvalidClientConfig,\n\t\t\tErr:        fmt.Errorf(\"HCP Authentication not configured, either set an HCP Client ID and secret using the environment variables %s and %s, place an HCP credential file in the default path (%s), or at a different path specified in the %s environment variable.\", env.HCPClientID, env.HCPClientSecret, env.HCPDefaultCredFilePathFull, env.HCPCredFile),\n\t\t}\n\t}\n\n\thcpClientCfg := httpclient.Config{\n\t\tSourceChannel: fmt.Sprintf(\"packer/%s\", version.PackerVersion.FormattedVersion()),\n\t}\n\tif err := hcpClientCfg.Canonicalize(); err != nil {\n\t\treturn nil, &ClientError{\n\t\t\tStatusCode: InvalidClientConfig,\n\t\t\tErr:        err,\n\t\t}\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/hcp/api/client.go#L25-L61","documentation":"NewClient in internal/hcp/api first asks env.HasHCPAuth() whether HCP credentials are present. If that check itself returns an error (as opposed to simply reporting no auth), the client returns a ClientError with StatusCode InvalidClientConfig wrapping `Failed to check for HCP auth, error: %s`. This distinguishes an error while inspecting the environment/credential file from the plain not-configured case.","triggerScenarios":"NewDeprecatedClient → NewClient runs env.HasHCPAuth(), which errors while reading the HCP credential file at the default or HCP_CREDENTIAL_FILE path (malformed file, permission error) or while evaluating the auth environment variables.","commonSituations":"HCP_CREDENTIAL_FILE points to a corrupt/unreadable credential file; permission denied on ~/.config/hcp/; an env-var read failing in a restricted environment.","solutions":["Inspect the wrapped inner error to see which credential source failed and fix that file/path","Point HCP_CREDENTIAL_FILE to a valid, readable credential file, or unset it to fall back to the default path","Prefer setting HCP_CLIENT_ID and HCP_CLIENT_SECRET env vars, which avoids credential-file reading","Recreate the credential file via `hcp auth login` if it is corrupt"],"exampleFix":"// before: broken custom credential file\nexport HCP_CREDENTIAL_FILE=/path/corrupt.json\n// after: use explicit env credentials\nexport HCP_CLIENT_ID=...\nexport HCP_CLIENT_SECRET=...","handlingStrategy":"try-catch","validationCode":"// Pre-check the credential file is readable JSON before constructing the client\nif p := os.Getenv(\"HCP_CREDENTIAL_FILE\"); p != \"\" {\n    f, err := os.Open(p)\n    if err != nil { return fmt.Errorf(\"HCP credential file unreadable: %w\", err) }\n    f.Close()\n}","typeGuard":null,"tryCatchPattern":"client, err := hcpapi.NewClient()\nvar ce *hcpapi.ClientError\nif errors.As(err, &ce) && ce.StatusCode == hcpapi.InvalidClientConfig {\n    return fmt.Errorf(\"HCP auth check failed: %v\", ce.Err)\n}","preventionTips":["Keep the HCP credential file readable by the running user","Validate HCP_CREDENTIAL_FILE points to an existing, well-formed file","Prefer env-var credentials to avoid file-reading paths","Recreate credentials with `hcp auth login` if corrupt"],"tags":["hcp","authentication","configuration"],"backgroundTag":"missing-hcp-auth","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"}