hasura/graphql-engine · error · errors.Error

parse file %w

Error message

parse file %w

What it means

After successfully reading the global config bytes, json.Unmarshal failed to parse them into rawGlobalConfig. This means the file exists and is readable but is not valid JSON or does not match the expected structure.

Source

Thrown at cli/global_config.go:60

	UUID                   *string     `json:"uuid"`
	EnableTelemetry        *bool       `json:"enable_telemetry"`
	ShowUpdateNotification *bool       `json:"show_update_notification"`
	CLIEnvironment         Environment `json:"cli_environment"`

	shoudlWrite bool
}

func (c *rawGlobalConfig) read(filename string) error {
	var op errors.Op = "cli.rawGlobalConfig.read"

	b, err := os.ReadFile(filename)
	if err != nil {
		return errors.E(op, fmt.Errorf("read file: %w", err))
	}

	err = json.Unmarshal(b, c)
	if err != nil {
		return errors.E(op, fmt.Errorf("parse file %w", err))
	}

	return nil
}

func (c *rawGlobalConfig) validateKeys() error {
	// check prescence of uuid, create if doesn't exist
	if c.UUID == nil {
		uid := uuid.NewString()
		c.UUID = &uid
		c.shoudlWrite = true
	}

	// check enabletelemetry
	if c.EnableTelemetry == nil {
		trueVal := true
		c.EnableTelemetry = &trueVal
		c.shoudlWrite = true

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Validate the file with a JSON linter: jq . ~/.config/tool/global.json and fix reported syntax errors
  2. Restore from backup or regenerate via init if the file is truncated
  3. Re-save without BOM and ensure UTF-8 encoding

Example fix

// before ({~/.config/tool/global.json})
{ "telemetry": true, }  // trailing comma
// after
{ "telemetry": true }
Defensive patterns

Strategy: try-catch

Validate before calling

b, err := os.ReadFile(configPath)
if err == nil {
    if !json.Valid(b) {
        log.Fatalf("global config is not valid JSON; run: jq . %s", configPath)
    }
}

Type guard

func isValidJSONConfig(b []byte) bool {
    return json.Valid(b)
}

Try / catch

if err := setupGlobalConfig(); err != nil {
    var synErr *json.SyntaxError
    if stderrors.As(err, &synErr) {
        // report synErr.Offset to pinpoint the bad character, then fix or regenerate the file
    }
}

Prevention

When it happens

Trigger: setupGlobalConfig reading a global config file containing malformed JSON — trailing commas, comments, single quotes, truncation from a concurrent write, or a BOM/UTF-16 encoding.

Common situations: Hand-edited config with JSON5-style syntax; file truncated by a crashed write; editor saving with BOM; secrets injected into the file with unescaped characters; two processes writing simultaneously.

Related errors


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