vitessio/vitess · error

panic(err)

Error message

panic(err)

What it means

MustParseGTID is the panicking variant of ParseGTID: it parses a GTID of a given flavor (e.g. "MySQL56", "MariaDB") and panics with the parse error instead of returning it. It exists for call sites where the input is known-valid (tests, constants); feeding it user-controlled or unparsed input turns a normal parse failure into a panic/crash.

Source

Thrown at go/mysql/replication/gtid.go:75

}

// gtidParsers maps flavor names to parser functions.
var gtidParsers = make(map[string]func(string) (GTID, error))

// ParseGTID calls the GTID parser for the specified flavor.
func ParseGTID(flavor, value string) (GTID, error) {
	parser := gtidParsers[flavor]
	if parser == nil {
		return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "parse error: unknown GTID flavor %#v", flavor)
	}
	return parser(value)
}

// MustParseGTID calls ParseGTID and panics on error.
func MustParseGTID(flavor, value string) GTID {
	gtid, err := ParseGTID(flavor, value)
	if err != nil {
		panic(err)
	}
	return gtid
}

// EncodeGTID returns a string that contains both the flavor and value of the
// GTID, so that the correct parser can be selected when that string is passed
// to DecodeGTID.
func EncodeGTID(gtid GTID) string {
	if gtid == nil {
		return ""
	}

	return fmt.Sprintf("%s/%s", gtid.Flavor(), gtid.String())
}

// DecodeGTID converts a string in the format returned by EncodeGTID back into
// a GTID interface value with the correct underlying flavor.
func DecodeGTID(s string) (GTID, error) {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Use ParseGTID and handle the error instead of the Must* variant for any runtime/user-supplied input
  2. Validate the GTID string format (flavor and value) before calling MustParseGTID
  3. Check that the flavor string matches the source server (MySQL56 vs MariaDB vs RocksmarTDB) — mixing flavors is a common cause

Example fix

// before
gtid := replication.MustParseGTID(flavor, cfg.GtidString)
// after
gtid, err := replication.ParseGTID(flavor, cfg.GtidString)
if err != nil {
	return vterrors.Wrapf(err, "invalid GTID %q for flavor %s", cfg.GtidString, flavor)
}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := replication.ParseGTID(flavor, value); err != nil {
	return err
}

Try / catch

func safeParseGTID(flavor, value string) (gtid replication.GTID, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("MustParseGTID panicked: %v", r)
		}
	}()
	return replication.MustParseGTID(flavor, value), nil
}

Prevention

When it happens

Trigger: Calling MustParseGTID(flavor, value) where ParseGTID fails: unknown flavor, malformed value like "ddd6e3a4-...:notanumber", or empty value.

Common situations: Passing server UUIDs/GTID strings read from config files, command-line flags, or topology data that contain typos or were produced by a different MySQL flavor.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/94aab9d632c26cdc. Report an issue: GitHub.