cayleygraph/cayley · error

could not open config file %q: %v

Error message

could not open config file %q: %v

What it means

LoadConf loads a gaedatastore Config from a JSON file. If os.Open fails (file missing, no permissions, bad path), the open error is wrapped in this message with the file path. It is a config-file open failure raised before any JSON decoding happens.

Source

Thrown at graph/gaedatastore/config.go:132

	f, err := strconv.ParseFloat(text, 64)
	*d = duration(time.Duration(f) * time.Second)
	return err
}

func (d *duration) MarshalJSON() ([]byte, error) {
	return []byte(fmt.Sprintf("%q", *d)), nil
}

// LoadConf reads a JSON-encoded config contained in the given file. A zero value
// config is returned if the filename is empty.
func LoadConf(file string) (*Config, error) {
	config := &Config{}
	if file == "" {
		return config, nil
	}
	f, err := os.Open(file)
	if err != nil {
		return nil, fmt.Errorf("could not open config file %q: %v", file, err)
	}
	defer f.Close()

	dec := json.NewDecoder(f)
	err = dec.Decode(config)
	if err != nil {
		return nil, fmt.Errorf("could not parse config file %q: %v", file, err)
	}
	return config, nil
}

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Verify the config file path exists and is spelled correctly (use an absolute path to avoid working-directory issues).
  2. Check file permissions so the Cayley process user can read it (chmod/chown as needed).
  3. Pass an empty file string if you intend to use the default zero-value Config instead of loading a file.
  4. Confirm the path points to a file, not a directory.

Example fix

// before
conf, err := gaedatastore.LoadConf("gaecfg.json") // relative path, file absent
// after
conf, err := gaedatastore.LoadConf("/app/config/gaedatastore.json") // absolute, existing path
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(path); err != nil {
    return fmt.Errorf("gaedatastore config not readable: %v", err)
}

Try / catch

conf, err := gaedatastore.LoadConf(path)
if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) {
        log.Fatalf("cannot open config %s: %v", path, pe)
    }
    return err
}

Prevention

When it happens

Trigger: Calling configFrom/LoadConf with a file path that does not exist, is a directory, or is not readable by the process (os.Open returns an error).

Common situations: Typo in the -config path on GAE datastore startup; running the process from a different working directory so a relative path no longer resolves; file permissions changed after deployment.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/d5c35e2057f86e64. Report an issue: GitHub.