feat: add boundary checks and error handling for Rating and State enums#5
Open
chenzihui222 wants to merge 1 commit into
Open
feat: add boundary checks and error handling for Rating and State enums#5chenzihui222 wants to merge 1 commit into
chenzihui222 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为 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 支持