nats-io/nats-server · error

invalid semver

Error message

invalid semver

What it means

versionComponents: the version string did not match the semver regex (no major.minor.patch captured), so version comparisons — leaf-node minimum-version checks, trusted-operator validation — fail. The unparsable version string from config or peer info is the input at fault.

Source

Thrown at server/util.go:46

	"strconv"
	"strings"
	"time"
)

// This map is used to store URLs string as the key with a reference count as
// the value. This is used to handle gossiped URLs such as connect_urls, etc..
type refCountedUrlSet map[string]int

// Ascii numbers 0-9
const (
	asciiZero = 48
	asciiNine = 57
)

func versionComponents(version string) (major, minor, patch int, err error) {
	m := semVerRe.FindStringSubmatch(version)
	if len(m) == 0 {
		return 0, 0, 0, errors.New("invalid semver")
	}
	major, err = strconv.Atoi(m[1])
	if err != nil {
		return -1, -1, -1, err
	}
	minor, err = strconv.Atoi(m[2])
	if err != nil {
		return -1, -1, -1, err
	}
	patch, err = strconv.Atoi(m[3])
	if err != nil {
		return -1, -1, -1, err
	}
	return major, minor, patch, err
}

func versionAtLeastCheckError(version string, emajor, eminor, epatch int) (bool, error) {
	major, minor, patch, err := versionComponents(version)

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Use full semver strings like 2.10.0 in minimum-version settings
  2. Fix or remove malformed version fields from operator/leafnode configuration
  3. Strip prefixes such as 'v' before comparing if needed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/util.go:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/ea88cf6817fd5ec0. Report an issue: GitHub.