ruby / ruby/error_highlight

Display a line in application code instead of gems

Aperta
#35 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Ruby
Stelle
155
Fork
37
Merge medio
4g 2h
PR unite (30g)
1

Descrizione

Currently, error_highlight spots the deepest Ruby frame. This may show code in a gem, which may not be very useful for application writers.

Consider:

# gem code
class SomeGem
  def foo(x)
    raise ArgumentError, "wrong input" if x == nil
  end
end

# app code
SomeGem.new.foo(nil)

Here is the current behavior:

$ ruby test.rb
test.rb:4:in `foo': wrong input (ArgumentError)

    raise ArgumentError, "wrong input" if x == nil
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from test.rb:9:in `<main>'

However, application writers may want to see the line of SomeGem.new.foo(nil).

How might this be resolved?

  1. Display code snippets for all frames, not just for the deepest one. Python does this, but I am not very keen on it because it makes the error trace very messy.
  2. Add an argument Kernel#raise to tell error_highlight which frame should be displayed, for example, raise ArgumentError, "wrong input", error_highlight_skip_frames: 1.

For 2, there are two ways how to show the error.

2-1. Keep the error trace as is and change only the snippet. This might be confusing because the snippet line does not exist in test.rb:4.

$ ruby test.rb
test.rb:4:in `foo': wrong input (ArgumentError)

SomeGem.new.foo(nil)
                ^^^
        from test.rb:9:in `<main>'

2-2. Skip the error trace. This looks good to me, but I think this is beyond the responsibilities of error_highlight.

$ ruby test.rb
test.rb:9:in `<main>': wrong input (ArgumentError)

SomeGem.new.foo(nil)
                ^^^

I wonder if we should put something like raise skip_frames: n in the Ruby core side? I need to organize my thoughts.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando la selezione attuale del frame più profondo in error_highlight e il comportamento di Ruby Kernel#raise discusso nell'issue. Confronta gli approcci proposti all-frames, skip-frame, snippet-only e trace-skipping, ma nota che l'issue non indica file o test e non stabilisce una condizione di completamento concordata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
ruby
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.