{"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":"validation","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/cos/backend_state.go#L138-L174","documentation":"Raised by Backend.client() (cos/backend_state.go:156) when the requested workspace/state name is empty or only whitespace. Every state operation requires a concrete name (default is provided by the caller as backend.DefaultStateName).","triggerScenarios":"client(\"\") or client(\"   \") - strings.TrimSpace(name) == \"\". Happens when a caller passes an unset workspace variable.","commonSituations":"A workspace variable resolved to empty in automation; a bug in calling code that did not default to 'default'.","solutions":["Pass a non-empty workspace name, or use 'default' for the default workspace.","Default unset workspace variables to 'default' in your scripts before invoking terraform.","Validate workspace names upstream before passing them to the backend."],"exampleFix":"// before\nWORKSPACE=\"\"\nterraform workspace select \"$WORKSPACE\"\n// after\nWORKSPACE=\"${WORKSPACE:-default}\"\nterraform workspace select \"$WORKSPACE\"","handlingStrategy":"validation","validationCode":"// Ensure a workspace name is non-empty before backend operations\nfunc validWorkspaceName(name string) error {\n    if strings.TrimSpace(name) == \"\" {\n        return fmt.Errorf(\"state name must not be empty\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default workspace variables to 'default' in automation.","Validate names before invoking terraform workspace commands.","Treat an empty name as a configuration bug."],"tags":["cos","tencentcloud","workspace","validation","empty-name"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}