gastownhall/beads · error

parsing central config %s: %w

Error message

parsing central config %s: %w

What it means

LoadCentralConfig wraps json.Unmarshal failures with "parsing central config %s: %w", including the file path. It means the central config exists and was read but is not valid JSON matching the Config schema.

Source

Thrown at internal/configfile/central_config.go:47

	}
	return filepath.Join(home, ".config", "beads", CentralConfigFileName)
}

// LoadCentralConfig reads the central server config from the given path.
// Returns (nil, nil) if the file does not exist (graceful skip).
// Returns an error only if the file exists but cannot be parsed.
func LoadCentralConfig(path string) (*Config, error) {
	data, err := os.ReadFile(path) // #nosec G304 - path from DefaultCentralConfigPath or env
	if os.IsNotExist(err) {
		return nil, nil
	}
	if err != nil {
		return nil, fmt.Errorf("reading central config: %w", err)
	}

	var cfg Config
	if err := json.Unmarshal(data, &cfg); err != nil {
		return nil, fmt.Errorf("parsing central config %s: %w", path, err)
	}
	return &cfg, nil
}

// ApplyCentralDefaults merges server-related fields from the central config
// into the per-project config, but only for fields that are at their zero
// value in the project config. Non-server fields (Database, DoltDatabase,
// DoltDataDir, ProjectID, etc.) are never inherited from the central config
// because they are inherently per-project.
//
// This is a no-op if central is nil.
func ApplyCentralDefaults(project *Config, central *Config) {
	if central == nil {
		return
	}

	// Server connection fields only — these are the fields that are
	// typically identical across all projects on a machine.

View on GitHub (pinned to 71377f2769)

Solutions

  1. Validate the JSON: `python3 -m json.tool <path>` or `jq . <path>` and fix the syntax error
  2. Remove merge-conflict markers (<<<<<<< ======= >>>>>>>) from the file
  3. Restore the file from git or a backup
  4. Check the wrapped inner error message for the exact line/offset of the JSON fault

Example fix

// before (central.json)
{"defaults": {"dolt.mode": server,}}
// after
{"defaults": {"dolt.mode": "server"}}
Defensive patterns

Strategy: validation

Validate before calling

data, _ := os.ReadFile(path)
if json.Unmarshal(data, &struct{}{}) != nil {
    // fix JSON before bd reads it: run python3 -m json.tool or jq . on the file
}

Try / catch

cfg, err := bd.LoadCentralConfig(path)
if err != nil {
    var perr *json.SyntaxError
    if errors.As(err, &perr) { /* perr.Offset locates the fault */ }
    return err
}

Prevention

When it happens

Trigger: LoadCentralConfig(path) when the file contains truncated JSON, comments, trailing commas, or fields of the wrong type (e.g. a string where a number is expected).

Common situations: Hand-edited central config with a syntax error; merge conflict markers left in the file; partial write from a crashed editor or interrupted sync.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/f5338f51dbc585bf. Report an issue: GitHub.