{"record":{"id":"7da7a1f930615c22","repo":"wavetermdev/waveterm","slug":"env-string-too-large-max-d-bytes","errorCode":null,"errorMessage":"env string too large (max %d bytes)","messagePattern":"env string too large \\(max (.+?) bytes\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/envutil/envutil.go","lineNumber":57,"sourceCode":"\t\tsb.WriteByte('\\x00')\n\t}\n\treturn sb.String()\n}\n\nfunc GetEnv(envStr string, key string) string {\n\tenvMap := EnvToMap(envStr)\n\treturn envMap[key]\n}\n\nfunc SetEnv(envStr string, key string, val string) (string, error) {\n\tif strings.ContainsAny(key, \"=\\x00\") {\n\t\treturn \"\", fmt.Errorf(\"key cannot contain '=' or '\\\\x00'\")\n\t}\n\tif strings.Contains(val, \"\\x00\") {\n\t\treturn \"\", fmt.Errorf(\"value cannot contain '\\\\x00'\")\n\t}\n\tif len(key)+len(val)+2+len(envStr) > MaxEnvSize {\n\t\treturn \"\", fmt.Errorf(\"env string too large (max %d bytes)\", MaxEnvSize)\n\t}\n\tenvMap := EnvToMap(envStr)\n\tenvMap[key] = val\n\trtnStr := MapToEnv(envMap)\n\treturn rtnStr, nil\n}\n\nfunc RmEnv(envStr string, key string) string {\n\tenvMap := EnvToMap(envStr)\n\tdelete(envMap, key)\n\treturn MapToEnv(envMap)\n}\n\nfunc SliceToEnv(env []string) string {\n\tvar sb strings.Builder\n\tfor _, envVar := range env {\n\t\tif len(envVar) == 0 {\n\t\t\tcontinue","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/envutil/envutil.go#L39-L75","documentation":"SetEnv returns this when the resulting serialized environment string (existing env block plus the new key/value pair) would exceed MaxEnvSize (1 MiB). Wave stores the block environment as a single serialized string, so the total size of the whole block env is capped to keep RPC payloads bounded. The write is rejected before mutating the env map.","triggerScenarios":"Calling SetEnv when len(key)+len(val)+2+len(existing env string) > 1024*1024. Typically adding a large value (e.g. embedding a token, cert, or JSON blob in an env var) to a block that already has many/large env vars.","commonSituations":"Embedding secrets or base64 blobs in env vars; accumulating dozens of env vars on a long-lived block; migrating environments that exceed the 1 MiB block-env limit.","solutions":["Reduce the size of the value being set (move large data to a file and store its path in the env var).","Remove unused env vars from the block environment (SetEnv with empty values or via the settings UI) before adding the new one.","Store large configuration in wave config files or the app's own storage instead of the block environment.","Split work across multiple blocks with smaller environments."],"exampleFix":"// before\nenvutil.SetEnv(envStr, \"CERT_BUNDLE\", string(pemBytes)) // errors if envStr+pemBytes > 1MiB\n\n// after\nos.WriteFile(\"/path/to/bundle.pem\", pemBytes, 0600)\nenvutil.SetEnv(envStr, \"CERT_BUNDLE_PATH\", \"/path/to/bundle.pem\")","handlingStrategy":"validation","validationCode":"// estimate current block env size before SetEnv\nexistingLen := len(envStr)\nif existingLen + len(key) + len(val) + 2 > 1024*1024 {\n    return fmt.Errorf(\"env var %q would exceed 1MiB block-env limit\", key)\n}\n_, err := envutil.SetEnv(envStr, key, val)","typeGuard":null,"tryCatchPattern":"// Go: check the returned error\nnewEnv, err := envutil.SetEnv(envStr, key, val)\nif err != nil && strings.Contains(err.Error(), \"env string too large\") {\n    // trim existing env or move value to a file, then retry\n}","preventionTips":["Keep env var values small; store large payloads in files and pass paths","Audit block environments periodically for stale/large variables","Check len(key)+len(val)+2+len(envStr) against MaxEnvSize before calling","Never embed certificates, blobs, or tokens directly in env vars"],"tags":["go","environment","size-limit"],"backgroundTag":"env-string-too-large","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}