bytebase/bytebase · error

failed to parse phone number

Error message

failed to parse phone number

What it means

Validate parses a human phone number into DingTalk mobile format via getDingTalkMobileFromPhone before looking up the user ID; a malformed phone fails here. The wrap preserves the underlying parse error so the developer knows what format was rejected.

Source

Thrown at backend/plugin/webhook/dingtalk/app.go:42

}

func newProvider(id, secret, robot string) *provider {
	return &provider{
		id:     id,
		secret: secret,
		robot:  robot,
		c:      &http.Client{},
	}
}

func Validate(ctx context.Context, id, secret, robot, phone string) error {
	p := newProvider(id, secret, robot)
	if err := p.refreshToken(ctx); err != nil {
		return errors.Wrapf(err, "failed to refresh token")
	}
	mobile, err := getDingTalkMobileFromPhone(phone)
	if err != nil {
		return errors.Wrapf(err, "failed to parse phone number")
	}
	id, err = p.getIDByPhone(ctx, mobile)
	if err != nil {
		return errors.Wrapf(err, "failed to get user id by phone")
	}
	if err := p.sendMessage(ctx, []string{id}, "test", "test"); err != nil {
		return errors.Wrapf(err, "failed to send test message")
	}
	return nil
}

func (p *provider) refreshToken(ctx context.Context) error {
	token, err := getTokenCached(ctx, p.c, p.id, p.secret)
	if err != nil {
		return errors.Wrapf(err, "failed to get token")
	}
	p.token = token
	return nil

View on GitHub (pinned to 1870550677)

Solutions

  1. Enter the phone in international format with country code, e.g. +8613800138000
  2. Strip spaces, dashes, and parentheses before saving the webhook IM setting
  3. Check getDingTalkMobileFromPhone's accepted pattern and normalize input accordingly
  4. Confirm the phone number is actually registered with a DingTalk account

Example fix

// before
phone := "138-0013-8000"
// after
phone := "+8613800138000"
Defensive patterns

Strategy: validation

Validate before calling

re := regexp.MustCompile(`^\+\d{7,15}$`)
if !re.MatchString(phone) { return errors.New("phone must be international format, e.g. +8613800138000") }

Prevention

When it happens

Trigger: validateIMSetting supplies a phone string missing a country code, containing spaces/dashes/parentheses, a non-digit extension, or an empty string, and getDingTalkMobileFromPhone cannot normalize it.

Common situations: Users entering local-format numbers (no +86) into DingTalk IM settings; copy-pasted numbers with formatting characters; phone fields bound to the wrong configuration value (e.g. a name instead of a number).

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/f5eb7508ed61721f. Report an issue: GitHub.