-
Notifications
You must be signed in to change notification settings - Fork 51
Raise ArgumentError more often #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make_row and maybe other functions might need to be reworked to return this as an error tuple and not an element of a list of rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this
TODO
, it probably should raise. Although what will most likely happen is that it won't be able to raise because the VM cannot allocate enough memory for the exception struct and message regardless. The programmer is going to be in for a world of pain.But hopefully on the flip side, is that if the VM is able to free some memory, this call unblocks and completes the raise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's also something I've been thinking about: would any of the current out_of_memory errors ever surface or would the app just be OOM-killed. I have seen these errors in all of SQLite Erlang/Elixir bindings I could find and in https://github.com/jlouis/enacl as well, but I wonder if those code paths were ever actually executed ...
I think trying to raise is still a good strategy though.
UPDATE: Went to see how enacl is doing it now, and it seems like they have removed
alloc_failed
atoms in favor of "internal_error": jlouis/enacl@59b9443#diff-43b9ee1b39907dcfc3d096225f5550664a88e3c8a100392e77a0dfb25082a634L171. And also removed many of error tuples in favor of raising exceptions as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's hard to say because I haven't experienced it yet. I don't know what happens with the VM when you try to allocate a term and there is no memory available. Looking at
enif_alloc
it returnsNULL
if it fails to allocate.Initially my target audience for this library was embedded Nerves devices and memory constrained machines running a small elixir application, so it's probably best to figure out a good strategy for handling out of memory. I suspect, probably the best thing to do is to preallocate with the atoms a term or an exception term to return when there is a memory problem. This in theory should not allocate more memory since we would have pre allocated it prior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR: #304