-
Notifications
You must be signed in to change notification settings - Fork 517
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
Fallback to the default error format when a file is empty #2931
Conversation
try | ||
case file:read_file(Source) of | ||
{ok, <<>>} -> | ||
{error, empty_file}; | ||
{ok, Bin} -> | ||
Splits = re:split(Bin, "(?:\n|\r\n|\r)", [{newline, anycrlf}]), | ||
{ok, lists:nth(Nth, Splits)}; | ||
{error, Reason} -> | ||
{error, Reason} | ||
end |
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.
try | |
case file:read_file(Source) of | |
{ok, <<>>} -> | |
{error, empty_file}; | |
{ok, Bin} -> | |
Splits = re:split(Bin, "(?:\n|\r\n|\r)", [{newline, anycrlf}]), | |
{ok, lists:nth(Nth, Splits)}; | |
{error, Reason} -> | |
{error, Reason} | |
end | |
try file:read_file(Source) of | |
{ok, <<>>} -> | |
{error, empty_file}; | |
{ok, Bin} -> | |
Splits = re:split(Bin, "(?:\n|\r\n|\r)", [{newline, anycrlf}]), | |
{ok, lists:nth(Nth, Splits)}; | |
{error, Reason} -> | |
{error, Reason} |
This might give you similar semantics but a cleaner result, although it won't capture errors in re:split
or lists:nth
anymore, so we can maybe disregard this.
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.
Removed the try/catch in ff987ad
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.
Tests are failing now. It seems we need the try/catch here to prevent a crash. I'll push a fix.
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.
Fixed in e383d3b
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.
Nice catch!
6f1e917
to
ff987ad
Compare
This change resolves a bad match error that occurs when a .erl file is empty by falling back to the default error format.
ff987ad
to
e383d3b
Compare
This change resolves a bad match error that occurs when a .erl file is empty by falling back to the default error format.
Before
After