{"record":{"id":"9ef1835573a80ab4","repo":"beego/beego","slug":"can-not-convert-the-field-s-s-default-value-s-9ef183","errorCode":null,"errorMessage":"can not convert the field[%s]'s default value[%s] to uint%d value: %w","messagePattern":"can not convert the field\\[(.+?)\\]'s default value\\[(.+?)\\] to uint(.+?) value: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/bean/tag_auto_wire_bean_factory.go","lineNumber":192,"sourceCode":"\t\t\t\tfn, fValue.Kind().String())\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (t *TagAutoWireBeanFactory) setFloatXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {\n\tif v, err := strconv.ParseFloat(dftValue, bitSize); err != nil {\n\t\treturn fmt.Errorf(\"can not convert the field[%s]'s default value[%s] to float%d value: %w\",\n\t\t\tfn, dftValue, bitSize, err)\n\t} else {\n\t\tfv.SetFloat(v)\n\t\treturn nil\n\t}\n}\n\nfunc (t *TagAutoWireBeanFactory) setUIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {\n\tif v, err := strconv.ParseUint(dftValue, 10, bitSize); err != nil {\n\t\treturn fmt.Errorf(\"can not convert the field[%s]'s default value[%s] to uint%d value: %w\",\n\t\t\tfn, dftValue, bitSize, err)\n\t} else {\n\t\tfv.SetUint(v)\n\t\treturn nil\n\t}\n}\n\nfunc (t *TagAutoWireBeanFactory) setIntXValue(dftValue string, bitSize int, fn string, fv reflect.Value) error {\n\tif v, err := strconv.ParseInt(dftValue, 10, bitSize); err != nil {\n\t\treturn fmt.Errorf(\"can not convert the field[%s]'s default value[%s] to int%d value: %w\",\n\t\t\tfn, dftValue, bitSize, err)\n\t} else {\n\t\tfv.SetInt(v)\n\t\treturn nil\n\t}\n}\n\nfunc (t *TagAutoWireBeanFactory) needInject(fValue reflect.Value) bool {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/beego/beego/blob/939cfde380bb9f15844ad633b84f037f7da21584/core/bean/tag_auto_wire_bean_factory.go#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"Negative defaults on uint fields; hex/octal literals from configs; oversized counts into uint8/uint16; values produced by a custom FieldTagParser without sanitization.","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"],"exampleFix":"// before\ntype Tier struct {\n    Level uint8 `default:\"-1\"`\n}\n// after\ntype Tier struct {\n    Level uint8 `default:\"255\"`\n}","handlingStrategy":"validation","validationCode":"func checkUintDefaults(v interface{}) error {\n    t := reflect.TypeOf(v)\n    if t.Kind() == reflect.Ptr { t = t.Elem() }\n    for i := 0; i < t.NumField(); i++ {\n        f := t.Field(i)\n        dv := f.Tag.Get(\"default\")\n        if dv == \"\" { continue }\n        switch f.Type.Kind() {\n        case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n            if _, err := strconv.ParseUint(dv, 10, f.Type.Bits()); err != nil {\n                return fmt.Errorf(\"field %s: uint default %q invalid\", f.Name, dv)\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unsigned fields get unsigned decimal defaults only","Range-check uint8/uint16/uint32 tags against MaxUint8/16/32","Reject leading '+'/'-' and separators in generated tags"],"tags":["beego","autowire","dependency-injection","type-conversion","struct-tag"],"backgroundTag":null,"analyzedSha":"939cfde380bb9f15844ad633b84f037f7da21584","analyzedAt":"2026-08-15T17:22:06.535Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}