lionsoul2014/ip2region · error

failed to create v4 config: %w

Error message

failed to create v4 config: %w

What it means

Go convenience constructor: building the default v4 config (open, verify, header/version check, vector-index load with 20 searchers) failed; the wrapped error pinpoints the failing step.

Source

Thrown at binding/golang/service/ip2region.go:103

		v6Pool:          v6Pool,
		v6InMemSearcher: v6InMemSearcher,
	}, nil
}

// create the ip2region search service with the specified v4 & v6 xdb path.
// with default cache policy VIndexCache and default searchers = 20
func NewIp2RegionWithPath(v4XdbPath string, v6XdbPath string) (*Ip2Region, error) {
	var err error

	// create v4 config with default config items
	var v4Config *Config
	if v4XdbPath == "" {
		v4Config = nil
	} else {
		v4Config, err = NewV4Config(VIndexCache, v4XdbPath, 20)
		if err != nil {
			return nil, fmt.Errorf("failed to create v4 config: %w", err)
		}
	}

	// create v6 config with default config items
	var v6Config *Config
	if v6XdbPath == "" {
		v6Config = nil
	} else {
		v6Config, err = NewV6Config(VIndexCache, v6XdbPath, 20)
		if err != nil {
			return nil, fmt.Errorf("failed to create v6 config: %w", err)
		}
	}

	return NewIp2Region(v4Config, v6Config)
}

func (ip2r *Ip2Region) Search(ip any) (string, error) {

View on GitHub (pinned to c1a1fc7d59)

Solutions

  1. Inspect the wrapped error (verify, version match, index load)
  2. Confirm the v4 xdb path points to a valid IPv4 database
  3. Fix/regenerate the file and call NewIp2RegionWithPath again
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at binding/golang/service/ip2region.go:103 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/4cab9353af960bce. Report an issue: GitHub.