hasura/graphql-engine · error · errors.Error
parse file
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.
Solutions
- Validate the file with a JSON linter: jq . ~/.config/tool/global.json and fix reported syntax errors
- Restore from backup or regenerate via init if the file is truncated
- 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
- Lint the config with jq after every manual edit
- Write configs atomically (temp file + rename) to avoid truncation
- Save as UTF-8 without BOM
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
- marshal file
- reading global config file failed
- cannot create global config directory
- cannot get home directory
- cannot read global config from file/env
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/1cdff441c7baf605.
Report an issue: GitHub.
Appendix: 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 = trueView on GitHub (pinned to 724551b9ae)