{"record":{"id":"1f0c3646da691a04","repo":"wavetermdev/waveterm","slug":"setting-auth-key-v","errorCode":null,"errorMessage":"setting auth key: %v","messagePattern":"setting auth key: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/server/main-server.go","lineNumber":402,"sourceCode":"\nfunc createMainWshClient() {\n\trpc := wshserver.GetMainRpcClient()\n\twshutil.DefaultRouter.RegisterTrustedLeaf(rpc, wshutil.DefaultRoute)\n\twps.Broker.SetClient(wshutil.DefaultRouter)\n\tlocalInitialEnv := envutil.PruneInitialEnv(envutil.SliceToMap(os.Environ()))\n\tsockName := wavebase.GetDomainSocketName()\n\tremoteImpl := wshremote.MakeRemoteRpcServerImpl(nil, wshutil.DefaultRouter, wshclient.GetBareRpcClient(), true, localInitialEnv, sockName)\n\tlocalConnWsh := wshutil.MakeWshRpc(wshrpc.RpcContext{Conn: wshrpc.LocalConnName}, remoteImpl, \"conn:local\")\n\tgo wshremote.RunSysInfoLoop(localConnWsh, wshrpc.LocalConnName)\n\twshutil.DefaultRouter.RegisterTrustedLeaf(localConnWsh, wshutil.MakeConnectionRouteId(wshrpc.LocalConnName))\n\twshfs.RpcClient = localConnWsh\n\twshfs.RpcClientRouteId = wshutil.MakeConnectionRouteId(wshrpc.LocalConnName)\n}\n\nfunc grabAndRemoveEnvVars() error {\n\terr := authkey.SetAuthKeyFromEnv()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"setting auth key: %v\", err)\n\t}\n\terr = wavebase.CacheAndRemoveEnvVars()\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = wcloud.CacheAndRemoveEnvVars()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Remove WAVETERM env vars that leak from prod => dev\n\tos.Unsetenv(\"WAVETERM_CLIENTID\")\n\tos.Unsetenv(\"WAVETERM_WORKSPACEID\")\n\tos.Unsetenv(\"WAVETERM_TABID\")\n\tos.Unsetenv(\"WAVETERM_BLOCKID\")\n\tos.Unsetenv(\"WAVETERM_CONN\")\n\tos.Unsetenv(\"WAVETERM_JWT\")\n\tos.Unsetenv(\"WAVETERM_VERSION\")","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/server/main-server.go#L384-L420","documentation":"The wave server requires an auth key and reads it from the environment via authkey.SetAuthKeyFromEnv during startup. If that fails (missing or invalid expected env vars), grabAndRemoveEnvVars wraps the cause as \"setting auth key: %v\" and aborts startup.","triggerScenarios":"Starting cmd/server (waveserver) when the auth-key environment variables are absent, malformed, or fail validation in authkey.SetAuthKeyFromEnv; the underlying error is appended after the colon.","commonSituations":"Running the server under a service manager that strips env vars; invoking the binary directly without the launcher that normally sets the auth key; stale/partial env after an upgrade.","solutions":["Launch the server via the official launcher (wlash/wave) which sets the auth key env vars.","Inspect the wrapped inner error for the precise env problem (missing var vs invalid format).","Set the expected auth-key env vars manually for the server process.","Ensure grabAndRemoveEnvVars runs before any code that consumes the env vars.","Verify no wrapper script unsets the relevant environment entries."],"exampleFix":"// before\nWAVESERVER_BIN   # run directly, no auth key in env -> startup error\n// after\nexport WAVE_AUTHKEY=<key-from-launcher>\nWAVESERVER_BIN   # or start via the wave launcher which sets the key","handlingStrategy":"validation","validationCode":"if os.Getenv(\"WAVE_AUTHKEY\") == \"\" { // whichever vars authkey expects\n    return fmt.Errorf(\"auth key env var missing; launch via the wave launcher\")\n}","typeGuard":null,"tryCatchPattern":"if err := grabAndRemoveEnvVars(); err != nil {\n    log.Fatalf(\"server startup failed: %v\", err) // inspect wrapped cause\n}","preventionTips":["Always start the server via the launcher that sets the auth key.","Don't sanitize/strip env vars in service definitions.","Read the wrapped inner error for missing vs invalid key details.","Keep launch scripts and server versions aligned."],"tags":["go","auth","environment","startup"],"backgroundTag":"missing-env-var","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}