lionsoul2014/ip2region · error

parse v4 cache policy: %w

Error message

parse v4 cache policy: %w

What it means

Go service factory: service.CachePolicyFromName rejected the v4 cache policy string; accepted (case-insensitive) names are file/nocache, vectorindex/vindex/vindexcache and content/buffercache, anything else wraps this error.

Source

Thrown at binding/golang/main.go:45

	if err != nil {
		return "", fmt.Errorf("failed to get executale: %w", err)
	}

	xdbPath := filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(binPath))), "/data/", fileName)
	_, err = os.Stat(xdbPath)
	if err != nil {
		return "", nil
	}

	// fmt.Printf("xdbPath=%s\n", xdbPath)
	return xdbPath, nil
}

func createService(v4XdbPath string, v4CachePolicy string, v6XdbPath string, v6CachePolicy string) (*service.Ip2Region, error) {
	// try to create v4 config
	v4CPolicy, err := service.CachePolicyFromName(v4CachePolicy)
	if err != nil {
		return nil, fmt.Errorf("parse v4 cache policy: %w", err)
	}

	v4DbPath, err := homedir.Expand(v4XdbPath)
	if err != nil {
		return nil, fmt.Errorf("Expand(`%s`): %s", v4XdbPath, err)
	}
	v4Config, err := service.NewV4Config(v4CPolicy, v4DbPath, 1)
	if err != nil {
		return nil, fmt.Errorf("NewV4Config: %w", err)
	}

	// try to create v6 config
	v6Policy, err := service.CachePolicyFromName(v6CachePolicy)
	if err != nil {
		return nil, fmt.Errorf("parse v6 cache policy: %w", err)
	}

	v6DbPath, err := homedir.Expand(v6XdbPath)

View on GitHub (pinned to c1a1fc7d59)

Solutions

  1. Use one of the accepted policy names: file/nocache, vectorindex/vindex/vindexcache, or content/buffercache
  2. Validate the policy string against service.CachePolicyFromName at config-load time
  3. Default to vectorIndex when the config value is absent
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at binding/golang/main.go:45 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02). Data as JSON: /api/errors/9f40b66384a8ee2f. Report an issue: GitHub.