Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| } | ||
| return T(v), nil | ||
| case int8: | ||
| if v < 0 || v >= int8(len(normalizedNames)) { |
There was a problem hiding this comment.
Integer overflow in int8 bounds check
Medium Severity
The cast int8(len(normalizedNames)) silently overflows when the names slice has 128 or more entries. Since T is ~uint8 and can represent up to 256 enum values, this is a reachable scenario. When overflowed (e.g., 130 names → int8(130) = −126), the comparison v >= -126 becomes true for all non-negative int8 values, incorrectly rejecting every valid input.
| if v < 0 || v >= float64(len(normalizedNames)) { | ||
| return unknown, fmt.Errorf("invalid %T value: %f", unknown, v) | ||
| } | ||
| return T(v), nil |
There was a problem hiding this comment.
Float values silently truncated to enum integers
Low Severity
Non-integer float values (e.g., float64(2.7)) pass the bounds check and are silently truncated by T(v), mapping them to an unrelated enum value. There's no check that the float is actually a whole number, so a value like 2.9 is quietly accepted as enum value 2.


Scope of changes
Adds generics based parsing for multiple types.
Estimated PR Size:
Acceptance criteria
This PR will be merged without review.
Author checklist
Note
Medium Risk
Introduces new generic parsing logic that accepts many input types and panics on invalid name schemas; while unit-tested, it could affect downstream behavior if relied on for input validation or error handling.
Overview
Adds a generic
ParseFactorythat builds enum parsers for~uint8enums, supporting case/whitespace-insensitive string parsing (via provided[]stringor[][]stringname tables) and numeric conversions with bounds checking.Introduces a central
Enuminterface bundling common enum behaviors (Stringer, JSON marshal/unmarshal, SQL scan/value), expands README with getting-started/theory docs, and adds comprehensive tests (plustestify) covering valid/invalid parse inputs and invalid name schemas.Written by Cursor Bugbot for commit 1156df2. Configure here.