{"record":{"id":"989e0585ce5b5f0f","repo":"hasura/graphql-engine","slug":"expected-a-valid-url-for-api-host-parsing-error","errorCode":null,"errorMessage":"expected a valid url for --api-host, parsing error: %w","messagePattern":"expected a valid url for --api-host, parsing error: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/console.go","lineNumber":76,"sourceCode":"\t\t\t\treturn errors.E(op, err)\n\t\t\t}\n\n\t\t\tif err := scripts.CheckIfUpdateToConfigV3IsRequired(ec); err != nil {\n\t\t\t\treturn errors.E(op, err)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\top := genOpName(cmd, \"RunE\")\n\t\t\tif cmd.Flags().Changed(\"api-host\") {\n\t\t\t\tvar err error\n\n\t\t\t\topts.APIHost, err = url.ParseRequestURI(apiHost)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.E(\n\t\t\t\t\t\top,\n\t\t\t\t\t\tfmt.Errorf(\"expected a valid url for --api-host, parsing error: %w\", err),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\topts.APIHost = &url.URL{\n\t\t\t\t\tScheme: \"http\",\n\t\t\t\t\tHost:   opts.Address,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\terr := opts.Run()\n\t\t\tif err != nil {\n\t\t\t\treturn errors.E(op, err)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t}\n\tf := consoleCmd.Flags()","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/console.go#L58-L94","documentation":"Thrown in the console command's PreRunE when the --api-host flag value fails url.ParseRequestURI. The CLI requires api-host to be a parseable absolute URI before it can construct the console API proxy URL; malformed values (missing scheme, spaces, stray characters) are rejected up front.","triggerScenarios":"Passing `--api-host localhost:8080` (no scheme), `--api-host https://hasura console api host`, or any value with whitespace/invalid URI characters; only values like https://api.example.com parse.","commonSituations":"Assuming host:port is accepted like other flags, copying a URL with a trailing slash/space from docs, or shell quoting issues injecting extra characters.","solutions":["Pass a full URI including scheme: `--api-host https://<host>` (port allowed: `https://host:port`).","Trim whitespace and check shell quoting of the flag value.","If you only meant to set the Hasura endpoint, use --endpoint instead."],"exampleFix":"# before\nhasura console --api-host localhost:9693\n# after\nhasura console --api-host http://localhost:9693","handlingStrategy":"validation","validationCode":"u, err := url.ParseRequestURI(apiHost)\nif err != nil || !u.IsAbs() {\n  log.Fatal(\"--api-host must be an absolute URL like https://host:port\")\n}","typeGuard":"func isValidAPIHost(s string) bool { u, err := url.ParseRequestURI(s); return err == nil && u.IsAbs() }","tryCatchPattern":"Catch the parse error, prepend a scheme (http:// or https://) to the host value, and re-run the console command.","preventionTips":["Always include the scheme in --api-host.","Validate URLs in wrapper scripts before calling the CLI.","Use --endpoint for the Hasura server URL."],"tags":["url-parsing","validation","cli-flags","hasura-cli"],"backgroundTag":"invalid-url-format","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}