Skip to content
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

Fix windows compatibility #114

Merged
merged 1 commit into from
Nov 12, 2021
Merged

Fix windows compatibility #114

merged 1 commit into from
Nov 12, 2021

Conversation

schneems
Copy link
Collaborator

@schneems schneems commented Nov 12, 2021

Previously I made the assumption that the filename would be the first part of the error message for a syntax error before the colon : while this is false, it is especially false on windows where every path starts with a drive letter and a colon such as c://hello/world.rb.

This commit fixes that problem by checking for the file on disk and appending more parts to the string.

This is not foolproof because an error message might be possible that someone is using a colon with a file that actually exists in front of it like:

/lol/foo.rb:imactuallyadirectory/realfile.rb

In this case if /lol/foo.rb existed then it would quit looking.

While I'm noting this edge case for completeness, I am not currently handling it. I think that case would be rare.

When SyntaxError is refactored in Ruby 3.2 then we don't have to rely on parsing out filenames anymore.

Close #111

Previously I made the assumption that the filename would be the first part of the error message for a syntax error before the colon `:` while this is false, it is especially false on windows where every path starts with a drive letter and a colon such as `c://hello/world.rb`.

This commit fixes that problem by checking for the file on disk and appending more parts to the string.

This is not foolproof because an error message might be possible that someone is using a colon with a file that actually exists in front of it like:

```
/lol/foo.rb:imactuallyadirectory/realfile.rb
```

In this case if `/lol/foo.rb` existed then it would quit looking.

While I'm noting this edge case for completeness, I am not currently handling it. I think case that would be rare. 

When SyntaxError is refactored in Ruby 3.2 then we don't have to rely on parsing out filenames anymore. 


Close #111
@schneems schneems merged commit 048a34e into main Nov 12, 2021
@schneems schneems deleted the schneems/fix-windows branch November 12, 2021 21:04
schneems added a commit that referenced this pull request Nov 20, 2021
As suggested in #119 (comment) we are now explicitly checking the type of the incoming error. Rather than raise a new error, I've chosen to emit a warning and re-raise the original error. This is a similar pattern to the case where we are not able to detect the filename from the error message. The goal is to provide visibility into the source of the behavior, but to break as few expectations as possible. 

The `DeadEnd.handle_error` should (ideally) never raise an error to the end user. The purpose of the library is to provide progressive error enhancement. If it fails it means we cannot make a better error, so therefore we should warn (so the user can fix or report the problem) and then fall back to the original error.

I also added a test for the failure error condition where the filename cannot be pulled out of the SyntaxError message which was added in #114.
schneems added a commit that referenced this pull request Nov 20, 2021
As suggested in #119 (comment) we are now explicitly checking the type of the incoming error. Rather than raise a new error, I've chosen to emit a warning and re-raise the original error. This is a similar pattern to the case where we are not able to detect the filename from the error message. The goal is to provide visibility into the source of the behavior, but to break as few expectations as possible. 

The `DeadEnd.handle_error` should (ideally) never raise an error to the end user. The purpose of the library is to provide progressive error enhancement. If it fails it means we cannot make a better error, so therefore we should warn (so the user can fix or report the problem) and then fall back to the original error.

I also added a test for the failure error condition where the filename cannot be pulled out of the SyntaxError message which was added in #114.
schneems added a commit that referenced this pull request Nov 21, 2021
* Add interface to require dead_end without core_ext

Currently `dead_end` works by monkey patching `require` and friends.

If someone wants to programmatically execute dead_end manually via `DeadEnd.handle_error` without monkey patches they can now do that by setting the environment variable `DISABLE_DEAD_END_CORE_EXT=1`.

* Move api to `dead_end/api` instead of env var

Because setting environment variables on systems may be difficult or inconsistent we are moving the API to be require based. Now anyone who wants to use dead_end without mutating `require` can do so via requiring `dead_end/api`.

* Update lib/dead_end/api.rb

Co-authored-by: Jake Zimmerman <zimmerman.jake@gmail.com>

* Add explicit check for Syntax Error

As suggested in #119 (comment) we are now explicitly checking the type of the incoming error. Rather than raise a new error, I've chosen to emit a warning and re-raise the original error. This is a similar pattern to the case where we are not able to detect the filename from the error message. The goal is to provide visibility into the source of the behavior, but to break as few expectations as possible. 

The `DeadEnd.handle_error` should (ideally) never raise an error to the end user. The purpose of the library is to provide progressive error enhancement. If it fails it means we cannot make a better error, so therefore we should warn (so the user can fix or report the problem) and then fall back to the original error.

I also added a test for the failure error condition where the filename cannot be pulled out of the SyntaxError message which was added in #114.

Co-authored-by: Jake Zimmerman <zimmerman.jake@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Failure/Error: source: Pathname(filename).read
1 participant