go-kratos/kratos · error

Enum '%s' range must be greater than 0 and less than or equa

Error message

Enum '%s' range must be greater than 0 and less than or equal to 600

What it means

Error "Enum '%s' range must be greater than 0 and less than or equal to 600" thrown in go-kratos/kratos.

Source

Thrown at cmd/protoc-gen-go-errors/errors.go:69

	for _, enum := range file.Enums {
		if !genErrorsReason(gen, file, g, enum) {
			index++
		}
	}
	// If all enums do not contain 'errors.code', the current file is skipped
	if index == 0 {
		g.Skip()
	}
}

func genErrorsReason(_ *protogen.Plugin, _ *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
	defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode)
	code := 0
	if ok := defaultCode.(int32); ok != 0 {
		code = int(ok)
	}
	if code > 600 || code < 0 {
		panic(fmt.Sprintf("Enum '%s' range must be greater than 0 and less than or equal to 600", string(enum.Desc.Name())))
	}
	var ew errorWrapper
	for _, v := range enum.Values {
		enumCode := code
		eCode := proto.GetExtension(v.Desc.Options(), errors.E_Code)
		if ok := eCode.(int32); ok != 0 {
			enumCode = int(ok)
		}
		// If the current enumeration does not contain 'errors.code'
		// or the code value exceeds the range, the current enum will be skipped
		if enumCode > 600 || enumCode < 0 {
			panic(fmt.Sprintf("Enum '%s' range must be greater than 0 and less than or equal to 600", string(v.Desc.Name())))
		}
		if enumCode == 0 {
			continue
		}

		comment := v.Comments.Leading.String()

View on GitHub (pinned to 668db92c2c)

When it happens

Trigger: Thrown at cmd/protoc-gen-go-errors/errors.go:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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