hasura/graphql-engine · error

error validating endpoint URL: %w

Error message

error validating endpoint URL: %w

What it means

The --endpoint value passed to `hasura init` failed url.ParseRequestURI validation. The CLI requires an absolute request URI, so relative or malformed endpoint strings are rejected before being written into config.yaml.

Source

Thrown at cli/commands/init.go:271

	err := os.MkdirAll(filepath.Dir(o.EC.ExecutionDirectory), os.ModePerm)
	if err != nil {
		return errors.E(op, fmt.Errorf("error creating setup directories: %w", err))
	}
	// set config object
	config := &cli.Config{
		Version: o.Version,
		ServerConfig: cli.ServerConfig{
			Endpoint: defaultEndpoint,
		},
		MetadataDirectory: "metadata",
		ActionConfig: &actionMetadataFileTypes.ActionExecutionConfig{
			Kind:                  "synchronous",
			HandlerWebhookBaseURL: "http://localhost:3000",
		},
	}
	if o.Endpoint != "" {
		if _, err := url.ParseRequestURI(o.Endpoint); err != nil {
			return errors.E(op, fmt.Errorf("error validating endpoint URL: %w", err))
		}

		config.Endpoint = o.Endpoint
	}

	if o.AdminSecret != "" {
		config.AdminSecret = o.AdminSecret
	}

	// write the config file
	o.EC.Config = config
	o.EC.ConfigFile = filepath.Join(o.EC.ExecutionDirectory, "config.yaml")

	err = o.EC.WriteConfig(nil)
	if err != nil {
		return errors.E(op, fmt.Errorf("cannot write config file: %w", err))
	}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Supply a fully-qualified URI including scheme: `--endpoint https://hasura.example.com`
  2. Trim whitespace and URL-encode special characters in the endpoint
  3. If using a local server, use http://localhost:8080 explicitly

Example fix

// before
hasura init myproject --endpoint localhost:8080
// after
hasura init myproject --endpoint http://localhost:8080
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.ParseRequestURI(endpoint)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
    log.Fatalf("endpoint must be an absolute http(s) URL, got %q", endpoint)
}

Type guard

func isValidEndpoint(s string) bool {
    u, err := url.ParseRequestURI(s)
    return err == nil && u.Host != "" && (u.Scheme == "http" || u.Scheme == "https")
}

Prevention

When it happens

Trigger: `hasura init --endpoint localhost:8080` (no scheme), `--endpoint /hasura`, or any string that is not a valid absolute URI.

Common situations: Forgetting the http:// or https:// scheme; trailing junk/whitespace in the endpoint; copying endpoint with unescaped characters.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/0606b93052fcd378. Report an issue: GitHub.