[ruby-core:112503] [Ruby master Feature#19451] Extract path and line number from SyntaxError?

Issue #19451 has been reported by ioquatix (Samuel Williams). ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by ioquatix (Samuel Williams). (and while we are at it, how about column information?) ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101947 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by zverok (Victor Shepelev). FWIW, `SyntaxError#path` [was added](https://rubyreferences.github.io/rubychanges/3.2.html#syntaxerrorpath) in 3.2 ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101951 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by Eregon (Benoit Daloze). The calling backtrace and the location of the error are separated things, so I don't think we should mix them. Adding `SyntaxError#lineno` would make sense IMO. ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101956 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by rubyFeedback (robert heiler). Is it #lineno or #line_number? I would think #line_number would look prettier, if we add a method to SyntaxError. (Not saying we should do, or not, either; just pointing at the different names above ^^^.) ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101958 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by schneems (Richard Schneeman). It's also worth mentioning that not all syntax errors have an associated path. `eval`, code piped to STDIN, and `ruby -e` can have invalid syntax but might not have an associated path. In the discussion around adding SyntaxSuggest to Ruby 3.2 I asked for something like `SyntaxError#source` that would let me access the source code for these elements, but it was not implemented before 3.2 was released. ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101960 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by nobu (Nobuyoshi Nakada). `SyntaxError` can contain multiple error locations. I'm trying https://github.com/nobu/ruby/tree/SyntaxError%23diagnostics. I can't get what "prepend them to backtrace_locations" means. ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101962 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by ioquatix (Samuel Williams). @nobu most text editors need a single line and column for each backtrace location. As it stands, just looking at the backtrack locations is not enough. For `SyntaxError`, the editor needs to know the "first location" which is the point the syntax error occurred. There are two ways this can be done: (1) SyntaxError#path / #line / #column information + SyntaxError#backtrace_locations (2) SyntaxError#backtrace_locations[0] contains the above `#path` `#line` and `#column` information, followed by the normal backtrace. By "prepend them to the backtrace_locations" I mean option (2), which is far easier for the editor to consume, since it won't have to know the specific details of how "SyntaxError" works, it will just put markers at each `backtrace_locations`, with the error details itself on `backtrace_locations[0]`. ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-101963 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/

Issue #19451 has been updated by mame (Yusuke Endoh). Unfortuantely, the description of this proposal is very poor. It is not at all clear what is being proposed for what use case. ---------------------------------------- Feature #19451: Extract path and line number from SyntaxError? https://bugs.ruby-lang.org/issues/19451#change-102163 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- There doesn't seem to be any official way to extract the path and line number from a syntax error. There are two ways I can see us dong this: - Provide explicit `path` and `line_number` attributes. - Prepend them to `backtrace_locations`. The nice thing about the latter approach is that it will just work with existing tools which understand how to highlight code based on backtrace locations. Maybe we should do both? -- https://bugs.ruby-lang.org/
participants (7)
-
Eregon (Benoit Daloze)
-
ioquatix (Samuel Williams)
-
mame (Yusuke Endoh)
-
nobu (Nobuyoshi Nakada)
-
rubyFeedback (robert heiler)
-
schneems (Richard Schneeman)
-
zverok (Victor Shepelev)