Skip to content

Conversation

@schneems
Copy link
Collaborator

When there is a syntax error inside of an eval, but the parent code is valid a syntax error is raised inside of the eval instead of inside the parent code. When this happens Ruby thinks the filename is (eval) but this does not exist on disk so dead end cannot read it. Here's the current behavior:

$ cat /tmp/scratch.rb
  $stderr = STDOUT
  eval("\"\xf0".force_encoding("utf-8"))
$ ruby -I./lib -rdead_end /tmp/scratch.rb
DeadEnd: Could not find filename from "(eval):1: invalid multibyte char (UTF-8) (SyntaxError)\n"
/tmp/scratch.rb:2:in `eval': (eval):1: invalid multibyte char (UTF-8) (SyntaxError)
(eval):1: unterminated string meets end of file
	from /tmp/scratch.rb:2:in `<main>'

Since we will never be able to read (eval):1 we can special case this "file name" and skip emitting the warning.

Same problem with code that is streamed to ruby:

$ echo "def foo" | ruby -rdead_end

However we're not currently capturing this error due to #31.

You can still get a warning by using DEBUG=1 environment variable for these cases in case there is a bug in this behavior and we need to debug it.

When there is a syntax error inside of an eval, but the parent code is valid a syntax error is raised inside of the eval instead of inside the parent code. When this happens Ruby thinks the filename is `(eval)` but this does not exist on disk so dead end cannot read it. Here's the current behavior:

```
$ cat /tmp/scratch.rb
  $stderr = STDOUT
  eval("\"\xf0".force_encoding("utf-8"))
$ ruby -I./lib -rdead_end /tmp/scratch.rb
DeadEnd: Could not find filename from "(eval):1: invalid multibyte char (UTF-8) (SyntaxError)\n"
/tmp/scratch.rb:2:in `eval': (eval):1: invalid multibyte char (UTF-8) (SyntaxError)
(eval):1: unterminated string meets end of file
	from /tmp/scratch.rb:2:in `<main>'
```

Since we will never be able to read `(eval):1` we can special case this "file name" and skip emitting the warning. 

Same problem with code that is streamed to ruby:

```
$ echo "def foo" | ruby -rdead_end
```

However we're not currently capturing this error due to #31. 

You can still get a warning by using `DEBUG=1` environment variable for these cases in case there is a bug in this behavior and we need to debug it.
@schneems schneems force-pushed the schneems/eval-and-stream branch from f8fff4e to 008d1c0 Compare May 24, 2022 15:23
@schneems schneems marked this pull request as ready for review May 24, 2022 15:23
@schneems schneems merged commit c11623e into main May 24, 2022
@schneems schneems deleted the schneems/eval-and-stream branch May 24, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants