You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
String.to_existing_atom/1 was chosen instead of String.to_atom/1 because we do not have control over the strings being converted, given that they come from a external source (Numscript-WASM), which may lead into a overload on our atoms table. The problem is that we did not load some of the atoms needed in any part of the app, thus failing in some points.
The solution was create structs, which not only solves the problem, but improve the legibility as well.
PR Type
enhancement, bug_fix, tests
Description
Introduced Posting and Balance structs for better atom management.
Updated type specifications to use new structs.
Enhanced tests to validate new struct implementations.
The calculate_final_balance function in Numscriptex.Balance might not handle cases where the asset or account is nil, which could lead to unexpected behavior or errors.
The from_list/1 function in Numscriptex.Posting has a duplicate @spec annotation, which could lead to confusion about the expected input and output types.
Why: The suggestion improves the type definition by ensuring that initial_balance and final_balance are non-negative integers, which is crucial for maintaining data integrity and preventing incorrect balance calculations.
High
Handle empty postings list safely
Ensure that the Balance.put/2 function handles cases where postings is an empty list to avoid potential runtime errors.
Why: This suggestion addresses a potential runtime error by ensuring that the Balance.put/2 function can handle cases where postings is an empty list. This is a significant improvement in terms of robustness and error handling.
Medium
Validate required keys in map
Ensure that the from_map/1 function checks for required keys in the input map to prevent incomplete Posting structs.
def from_map(map) do
+ required_keys = [:amount, :asset, :destination, :source]+ Enum.each(required_keys, fn key ->+ if Map.has_key?(map, key) == false, do: raise ArgumentError, "Missing key: #{key}"+ end)
struct(%__MODULE__{}, map)
end
Suggestion importance[1-10]: 8
__
Why: This suggestion enhances the from_map/1 function by adding a check for required keys, preventing the creation of incomplete Posting structs. This validation is important for ensuring data consistency and avoiding runtime errors due to missing keys.
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
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.
User description
String.to_existing_atom/1was chosen instead ofString.to_atom/1because we do not have control over the strings being converted, given that they come from a external source (Numscript-WASM), which may lead into a overload on our atoms table. The problem is that we did not load some of the atoms needed in any part of the app, thus failing in some points.The solution was create structs, which not only solves the problem, but improve the legibility as well.
PR Type
enhancement, bug_fix, tests
Description
Introduced
PostingandBalancestructs for better atom management.Updated type specifications to use new structs.
Enhanced tests to validate new struct implementations.
Updated README to reflect new struct usage.
Changes walkthrough 📝
3 files
Refactor to use `Posting` and `Balance` structsImplement `Balance` struct and related functionsImplement `Posting` struct and conversion functions2 files
Minor formatting changesMinor formatting changes4 files
Update tests for `Balance` structCorrect test description for `CheckLog`Add tests for `Posting` structUpdate integration tests for new structs1 files
Update documentation for new struct usage