{"record":{"id":"9b9676280e43b757","repo":"kataras/iris","slug":"sqlx-register-q-s","errorCode":null,"errorMessage":"sqlx: register: %q: %s","messagePattern":"sqlx: register: %q: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/sqlx/sqlx.go","lineNumber":86,"sourceCode":"// Register caches a struct value to the schema.\nfunc (s *Schema) Register(tableName string, value any) *Schema {\n\ttyp := reflect.TypeOf(value)\n\tfor typ.Kind() == reflect.Ptr {\n\t\ttyp = typ.Elem()\n\t}\n\n\tif tableName == \"\" {\n\t\t// convert to a human name, e.g. sqlx.Food -> food.\n\t\ttypeName := typ.String()\n\t\tif idx := strings.LastIndexByte(typeName, '.'); idx > 0 && len(typeName) > idx {\n\t\t\ttypeName = typeName[idx+1:]\n\t\t}\n\t\ttableName = snakeCase(typeName)\n\t}\n\n\tcolumns, err := convertStructToColumns(typ, s.ColumnNameFunc)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"sqlx: register: %q: %s\", reflect.TypeOf(value).String(), err.Error()))\n\t}\n\n\ts.Rows[typ] = &Row{\n\t\tSchema:     s.Name,\n\t\tName:       tableName,\n\t\tStructType: typ,\n\t\tColumns:    columns,\n\t}\n\n\treturn s\n}\n\n// Query is a shortcut of executing a query and bind the result to \"dst\".\nfunc (s *Schema) Query(ctx context.Context, db *sql.DB, dst any, query string, args ...any) error {\n\trows, err := db.QueryContext(ctx, query, args...)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/sqlx/sqlx.go#L68-L104","documentation":"Register reflects over the struct to derive columns via convertStructToColumns; if that fails (e.g. unsupported struct shape) it panics with the value's type and the underlying error, prefixed 'sqlx: register:'.","triggerScenarios":"Calling s.Register(value) with a struct that convertStructToColumns cannot process — typically a struct with no exportable/valid columns or a field configuration error under the configured ColumnNameFunc.","commonSituations":"Registering an empty struct, a struct with only unexported fields, or a misconfigured custom ColumnNameFunc producing invalid column names.","solutions":["Ensure the registered type has at least one exported field usable as a column","Check the custom ColumnNameFunc doesn't produce empty/invalid names","Log/handle the error by recovering around Register at startup"],"exampleFix":"// before\ntype user struct {\n    name string // unexported\n}\ndb.Register(user{})\n// after\ntype User struct {\n    Name string `db:\"name\"`\n}\ndb.Register(User{})","handlingStrategy":"validation","validationCode":"func registrable(v any) bool {\n    t := reflect.TypeOf(v)\n    if t.Kind() != reflect.Struct { return false }\n    for i := 0; i < t.NumField(); i++ {\n        if t.Field(i).PkgPath == \"\" { return true } // has exported field\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Fatalf(\"sqlx register failed: %v\", r) } }()\ndb.Register(Model{})","preventionTips":["Register models with exported, db-tagged fields","Test Register calls at startup with a recover that fails fast with context","Review custom ColumnNameFunc outputs for empty/invalid names"],"tags":["go","panic","sqlx","reflection","schema"],"backgroundTag":"schema-registration-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}