{"record":{"id":"b48035a89c60baae","repo":"cloudflare/cloudflared","slug":"tunnel-name-required","errorCode":null,"errorMessage":"tunnel name required","messagePattern":"tunnel name required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/tunnel.go","lineNumber":94,"sourceCode":"}\n\nfunc NewCleanupParams() *CleanupParams {\n\treturn &CleanupParams{\n\t\tqueryParams: url.Values{},\n\t}\n}\n\nfunc (cp *CleanupParams) ForClient(clientID uuid.UUID) {\n\tcp.queryParams.Set(\"client_id\", clientID.String())\n}\n\nfunc (cp CleanupParams) encode() string {\n\treturn cp.queryParams.Encode()\n}\n\nfunc (r *RESTClient) CreateTunnel(name string, tunnelSecret []byte) (*TunnelWithToken, error) {\n\tif name == \"\" {\n\t\treturn nil, errors.New(\"tunnel name required\")\n\t}\n\tif _, err := uuid.Parse(name); err == nil {\n\t\treturn nil, errors.New(\"you cannot use UUIDs as tunnel names\")\n\t}\n\tbody := &newTunnel{\n\t\tName:         name,\n\t\tTunnelSecret: tunnelSecret,\n\t}\n\n\tresp, err := r.sendRequest(\"POST\", r.baseEndpoints.accountLevel, body)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"REST request failed\")\n\t}\n\tdefer resp.Body.Close()\n\n\tswitch resp.StatusCode {\n\tcase http.StatusOK:\n\t\tvar tunnel TunnelWithToken","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/tunnel.go#L76-L112","documentation":"CreateTunnel rejects an empty name string before making any API call, returning this client-side validation error. Tunnel names are required by the Cloudflare API and cloudflared validates locally to fail fast. No network request is made when this error occurs.","triggerScenarios":"Calling RESTClient.CreateTunnel with \"\" as the name — typically from an unset config value, empty environment variable, or CLI flag that defaulted to empty.","commonSituations":"Config files missing the tunnel name field; shell variables expanding to empty (e.g. $TUNNEL_NAME unset in CI); scripting errors passing the wrong positional argument.","solutions":["Provide a non-empty tunnel name to CreateTunnel","Check the config/env source of the name for typos or unset variables","Add caller-side validation with a clear message before invoking the client"],"exampleFix":"// before\nname := os.Getenv(\"TUNNEL_NAME\")\ntunnel, err := client.CreateTunnel(name, secret)\n// after\nname := os.Getenv(\"TUNNEL_NAME\")\nif name == \"\" {\n    return errors.New(\"TUNNEL_NAME must be set to a non-empty tunnel name\")\n}\ntunnel, err := client.CreateTunnel(name, secret)","handlingStrategy":"validation","validationCode":"if name == \"\" {\n    return errors.New(\"tunnel name must be non-empty before calling CreateTunnel\")\n}","typeGuard":null,"tryCatchPattern":"t, err := client.CreateTunnel(name, secret)\nif err != nil && strings.Contains(err.Error(), \"tunnel name required\") {\n    return fmt.Errorf(\"invalid tunnel config: name is empty: %w\", err)\n}","preventionTips":["Validate config-derived values before constructing client calls","Fail fast in scripts when required env vars are unset","Use config schema validation for tunnel configuration files","Log which source (flag/env/file) the empty name came from"],"tags":["validation","tunnel","cloudflare"],"backgroundTag":"empty-required-field","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}