beego/beego · error
can not convert the field[%s]'s default value[%s] to uint%d
Error message
can not convert the field[%s]'s default value[%s] to uint%d value: %w
What it means
TagAutoWireBeanFactory.AutoWire's setUIntXValue converts `default:` tag values into unsigned fields via strconv.ParseUint(value, 10, bitSize). Values that are not plain decimal unsigned literals — signs, hex, spaces, or values over the width — return this error including field name, value, width, and the wrapped strconv error.
Source
Thrown at core/bean/tag_auto_wire_bean_factory.go:192
fn, fValue.Kind().String())
}
}
return nil
}
func (t *TagAutoWireBeanFactory) setFloatXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
if v, err := strconv.ParseFloat(dftValue, bitSize); err != nil {
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to float%d value: %w",
fn, dftValue, bitSize, err)
} else {
fv.SetFloat(v)
return nil
}
}
func (t *TagAutoWireBeanFactory) setUIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
if v, err := strconv.ParseUint(dftValue, 10, bitSize); err != nil {
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to uint%d value: %w",
fn, dftValue, bitSize, err)
} else {
fv.SetUint(v)
return nil
}
}
func (t *TagAutoWireBeanFactory) setIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {
if v, err := strconv.ParseInt(dftValue, 10, bitSize); err != nil {
return fmt.Errorf("can not convert the field[%s]'s default value[%s] to int%d value: %w",
fn, dftValue, bitSize, err)
} else {
fv.SetInt(v)
return nil
}
}
func (t *TagAutoWireBeanFactory) needInject(fValue reflect.Value) bool {View on GitHub (pinned to 939cfde380)
Solutions
- Use a plain decimal integer within the field's range (uint8: 0..255)
- Widen the field type if the value is legitimately larger
- Strip formatting in a custom FieldTagParser before it returns DftValue
- Add CI validation of all default tags against their field kinds
Example fix
// before
type Tier struct {
Level uint8 `default:"-1"`
}
// after
type Tier struct {
Level uint8 `default:"255"`
} Defensive patterns
Strategy: validation
Validate before calling
func checkUintDefaults(v interface{}) error {
t := reflect.TypeOf(v)
if t.Kind() == reflect.Ptr { t = t.Elem() }
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
dv := f.Tag.Get("default")
if dv == "" { continue }
switch f.Type.Kind() {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if _, err := strconv.ParseUint(dv, 10, f.Type.Bits()); err != nil {
return fmt.Errorf("field %s: uint default %q invalid", f.Name, dv)
}
}
}
return nil
} Prevention
- Unsigned fields get unsigned decimal defaults only
- Range-check uint8/uint16/uint32 tags against MaxUint8/16/32
- Reject leading '+'/'-' and separators in generated tags
When it happens
Trigger: A bean field `Level uint8 \`default:"300"\`` (range overflow), `default:"-1"`, `default:"0x0F"`, or `default:"1 000"` when the bean factory autowires the zero-valued field.
Common situations: Negative defaults on uint fields; hex/octal literals from configs; oversized counts into uint8/uint16; values produced by a custom FieldTagParser without sanitization.
Related errors
- can not convert the field[%s]'s default value[%s] to bool va
- can not convert the field[%s]'s default value[%s] to float%d
- can not convert the field[%s]'s default value[%s] to int%d v
- Raw value: `%v` %s
- wrong digits/decimals value %s/%s
AI-assisted analysis of beego/beego@939cfde380 (2026-08-15).
Data as JSON: /api/errors/9ef1835573a80ab4.
Report an issue: GitHub.