feat: print template line numbers for errors when rendering ERB
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start in lib/krane/renderer.rb, where the three template-rendering errors are re-raised, and lib/krane/render_task.rb, where the error message is assembled. Trace how exception backtraces and content reach the logger, then verify that errors show the original stacktrace and numbered merged template content.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature request
- If the maintainers agree with the feature as described here, I intend to submit a Pull Request myself.1 (I would, because I already have the patch described locally, but this is a minor fix and I'd need to wait for our legal dept to clear the CLA)
Proposal: [provide details on the behaviour you'd like to see and why it would be useful]
When there is an error in the values interpolated into the templates, or an error with the partials, the message is confusing to developers because it does not indicate where the error occurred: eg:
[FATAL][2020-03-17 16:47:02 +0530] Invalid template: deployment.yml.erb
[FATAL][2020-03-17 16:47:02 +0530] > Error message:
[FATAL][2020-03-17 16:47:02 +0530] undefined method `[]' for nil:NilClass
(followed by a 300 line template). This happens for 3 reasons:
- the stacktrace isn't printed as part of the error;
- it turns out the stacktraces that are collected are not useful because exceptions are re-thrown without their original context;
- to understand the line number from the erb, you need to know the line numbering of the merged template, not the numbering from the file on disk.
Point (2): in lib/krane/renderer.rb, there are 3 lines where an error is caught and thrown without its context. In each case a line like:
raise InvalidTemplateError.new(err.message, filename: filename, content: raw_template)
should be replaced with a line like:
raise InvalidTemplateError.new(err.message, filename: filename, content: raw_template), err.message, err.backtrace
Next point (1): in lib/krane/render_task.rb, to print this, we need something like:
debug_msg += "> Stacktrace:\n#{FormattedLogger.indent_four(exception.backtrace.join("\n"))}"
(depending where you print this you will need to add other newlines to debug_msg).
This together with the fix for (2) means we get traces like:
[FATAL][2020-03-17 12:24:46 +0000] > Stacktrace:
[FATAL][2020-03-17 12:24:46 +0000] (erb):80:in `template_binding'
[FATAL][2020-03-17 12:24:46 +0000] /Users/bewins/.rbenv/versions/2.5.3/lib/ruby/2.5.0/erb.rb:876:in `eval'
Finally to understand what line 80 means in the above, we need to show the numbering of the template. One possible implementation is below:
numbered = exception.content.lines.map.with_index {|item, index| sprintf("% 4d: %s", index + 1, item)}
debug_msg += "\n> Template content:\n#{FormattedLogger.indent_four(numbered).join("")}"
1 This is the quickest way to get a new feature! We reserve the right to close feature requests, even ones we like, if the proposer does not intend to contribute to the feature and it doesn't fit in our current roadmap.
- Lingua principale
- Ruby
- Stelle
- 1.4k
- Fork
- 119
- Merge medio
- 1h 7m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Shopify/krane
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
:sparkles: enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
-
:sparkles: enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Tutte le issue di Shopify/krane
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
hanami/hanami-action#536 ·
-
[2026-11] Latest release (2026-11) still has expanded list entries that are no longer supportedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Shopify/product-taxonomy#1054 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 13 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
docker/model-runner#1118 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
TarteelAI/quranic-universal-library#1111 ·
I maintainer di solito rispondono entro 1 giorno