go-kratos/kratos · error

ErrorCode: %d

Error message

ErrorCode: %d

What it means

Bilibili Discovery client: when cancelling a watch, the server answered with an application code that is neither OK nor NotFound, and the numeric code is wrapped as 'ErrorCode: %d'. The client logs a warning and switches to the next Discovery node, so this surfaces mainly as an error from cancel/close paths.

Source

Thrown at contrib/registry/discovery/discovery.go:293

	// send request to Discovery server.
	if _, err = d.httpClient.R().
		SetContext(context.Background()).
		SetQueryParamsFromValues(p).
		SetResult(&res).
		Post(uri); err != nil {
		d.switchNode()
		log.Error("Discovery: cancel client.Get failed", "uri", uri, "env", config.Env, "appid", ins.AppID, "hostname", config.Host, "error", err)
		return
	}

	// handle response error
	if res.Code != _codeOK {
		if res.Code == _codeNotFound {
			return nil
		}

		log.Warn("Discovery: cancel client.Get returned code", "uri", uri, "env", config.Env, "appid", ins.AppID, "hostname", config.Host, "code", res.Code)
		err = fmt.Errorf("ErrorCode: %d", res.Code)
		return
	}

	return
}

func (d *Discovery) broadcast(apps map[string]*disInstancesInfo) {
	for appID, v := range apps {
		var count int
		// v maybe nil in old version(less than v1.1) Discovery, check in case of panic
		if v == nil {
			continue
		}
		for zone, ins := range v.Instances {
			if len(ins) == 0 {
				delete(v.Instances, zone)
			}
			count += len(ins)

View on GitHub (pinned to 668db92c2c)

Solutions

  1. Verify appid/env/hostname config matches what the Discovery server expects
  2. Check Discovery server logs to map the numeric code to its cause
  3. Do not treat cancel/close failures as fatal on shutdown paths — the client already switched nodes
  4. Align client and Discovery server versions if skew persists
Defensive patterns

Strategy: try-catch

Try / catch

if err := disc.Close(); err != nil {
    if strings.HasPrefix(err.Error(), "ErrorCode:") {
        // server rejected the cancel; the client already switched nodes
        log.Debug("discovery cancel rejected:", err)
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling the Discovery client's Cancel path; the cancel request to the Discovery server returns res.Code != _codeOK and != _codeNotFound, so the code is wrapped into an error.

Common situations: Mismatched appid/env between client and server; permission/auth rejection of the cancel; Discovery server version skew; node switching mid-request.

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/223b2e699fc413cd. Report an issue: GitHub.