Skip to content

feat: add boundary checks and error handling for Rating and State enums#5

Open
chenzihui222 wants to merge 1 commit into
knowecon:mainfrom
chenzihui222:feat/enum-boundary-checks
Open

feat: add boundary checks and error handling for Rating and State enums#5
chenzihui222 wants to merge 1 commit into
knowecon:mainfrom
chenzihui222:feat/enum-boundary-checks

Conversation

@chenzihui222

Copy link
Copy Markdown

为 Rating 和 State 枚举添加边界检查和错误处理,提高API健壮性。\n\n## Changes\n- from_int/1 返回 {:ok, value} | :error tuple\n- 新增 from_int!/1 在无效输入时抛出 ArgumentError\n- 新增 valid?/1 用于快速验证\n- 更新 @SPEC 类型以获得更好的 dialyzer 支持

Add proper input validation for enum conversion functions:

- from_int/1 now returns {:ok, value} | :error tuple
- Add from_int!/1 with explicit ArgumentError on invalid input
- Add valid?/1 for quick validation checks
- Update @SPEC types for better dialyzer support
- Add comprehensive @doc with examples

This improves API robustness and provides better error messages
for invalid enum values instead of FunctionClauseError.
@chenzihui222 chenzihui222 marked this pull request as ready for review March 9, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant