{"record":{"id":"2ca56847af02ca14","repo":"hashicorp/terraform","slug":"state-name-not-allow-to-be-empty","errorCode":null,"errorMessage":"state name not allow to be empty","messagePattern":"state name not allow to be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/cos/backend_state.go","lineNumber":156,"sourceCode":"\t\t\tif err := stateMgr.PersistState(nil); err != nil {\n\t\t\t\terr = lockUnlock(err)\n\t\t\t\treturn nil, diags.Append(err)\n\t\t\t}\n\t\t}\n\n\t\t// Unlock, the state should now be initialized\n\t\tif err := lockUnlock(nil); err != nil {\n\t\t\treturn nil, diags.Append(err)\n\t\t}\n\t}\n\n\treturn stateMgr, diags\n}\n\n// client returns a remoteClient for the named state.\nfunc (b *Backend) client(name string) (*remoteClient, error) {\n\tif strings.TrimSpace(name) == \"\" {\n\t\treturn nil, fmt.Errorf(\"state name not allow to be empty\")\n\t}\n\n\treturn &remoteClient{\n\t\tcosContext: b.cosContext,\n\t\tcosClient:  b.cosClient,\n\t\ttagClient:  b.tagClient,\n\t\tbucket:     b.bucket,\n\t\tstateFile:  b.stateFile(name),\n\t\tlockFile:   b.lockFile(name),\n\t\tencrypt:    b.encrypt,\n\t\tacl:        b.acl,\n\t}, nil\n}\n\n// stateFile returns state file path by name\nfunc (b *Backend) stateFile(name string) string {\n\tif name == backend.DefaultStateName {\n\t\treturn path.Join(b.prefix, b.key)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/cos/backend_state.go#L138-L174","documentation":"Backend.client(name) builds a remoteClient whose stateFile and lockFile are derived from the name. It rejects empty or whitespace-only names with strings.TrimSpace(name) == \"\" because the resulting object key would be malformed.","triggerScenarios":"b.client(\"\") or b.client(\"   \") invoked from DeleteWorkspace/StateMgr.","commonSituations":"Bug in workspace-name plumbing upstream; a script calling the backend API with an empty workspace name; a workspace created with an empty name through some unsupported path.","solutions":["Pass a non-empty workspace name.","Use `terraform workspace new/select <name>` with a valid, non-empty name."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Reject empty workspace names before invoking the backend.\nfunc safeClient(b *Backend, name string) (*remoteClient, error) {\n    if strings.TrimSpace(name) == \"\" {\n        return nil, fmt.Errorf(\"state name not allow to be empty\")\n    }\n    return b.client(name)\n}","typeGuard":"// isValidWorkspaceName reports whether name is usable for the COS backend.\nfunc isValidWorkspaceName(name string) bool {\n    return strings.TrimSpace(name) != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always pass a concrete workspace name from upstream code.","Use terraform workspace new/select with a non-empty name.","Lint automation that constructs workspace names to forbid empty.","Unit-test name plumbing when integrating the backend."],"tags":["cos","tencent-cloud","workspace","validation","backend"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}