mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
fix: typos in pipe arguments (i.e. format) now show a proper diagnostic.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- Polish existing features before moving on to new ones.
|
- Polish existing features before moving on to new ones.
|
||||||
- [ ] Improve diagnostics
|
- [ ] Improve diagnostics
|
||||||
|
- [ ] keep track of every error and don't report them more than once.
|
||||||
- [ ] All Diagnostics should show:
|
- [ ] All Diagnostics should show:
|
||||||
- [ ] *What* went wrong
|
- [ ] *What* went wrong
|
||||||
- [ ] *where* (in the file)
|
- [ ] *where* (in the file)
|
||||||
|
|||||||
@@ -393,4 +393,3 @@ parse_config_menus :: proc(
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -309,14 +309,18 @@ write_gutter :: proc(sb: ^strings.Builder, width: int, faint: string, reset: str
|
|||||||
|
|
||||||
// format_render_error produces a diagnostic for an Error value using the
|
// format_render_error produces a diagnostic for an Error value using the
|
||||||
// template's path and source for context. Returns "" for nil errors.
|
// template's path and source for context. Returns "" for nil errors.
|
||||||
|
// If the error carries its own source/path (from tag_error), those are used
|
||||||
|
// instead of the passed-in template — this ensures errors inside partials
|
||||||
|
// point at the correct file.
|
||||||
format_render_error :: proc(err: Error, tmpl: Template, colorize: bool = false) -> string {
|
format_render_error :: proc(err: Error, tmpl: Template, colorize: bool = false) -> string {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
path := tmpl.path
|
b := body(err)
|
||||||
|
source := b.source != "" ? b.source : tmpl.source
|
||||||
|
path := b.path != "" ? b.path : tmpl.path
|
||||||
if path == "" {
|
if path == "" {
|
||||||
path = "<input>"
|
path = "<input>"
|
||||||
}
|
}
|
||||||
b := body(err)
|
return format_error(path, source, b.pos, b.msg, colorize = colorize)
|
||||||
return format_error(path, tmpl.source, b.pos, b.msg, colorize = colorize)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-7
@@ -26,9 +26,11 @@ Error_Kind :: enum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error_Body :: struct {
|
Error_Body :: struct {
|
||||||
msg: string,
|
msg: string,
|
||||||
pos: int,
|
pos: int,
|
||||||
kind: Error_Kind,
|
kind: Error_Kind,
|
||||||
|
source: string,
|
||||||
|
path: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error is nil when no error occurred.
|
// Error is nil when no error occurred.
|
||||||
@@ -47,6 +49,20 @@ body :: proc(err: Error) -> Error_Body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tag_error stamps an Error with the source/path of the template where it
|
||||||
|
// originated, so diagnostics point at the correct file (e.g. a partial).
|
||||||
|
tag_error :: proc(err: Error, tmpl: Template) -> Error {
|
||||||
|
if err == nil do return nil
|
||||||
|
b := body(err)
|
||||||
|
return Error_Body {
|
||||||
|
msg = b.msg,
|
||||||
|
pos = b.pos,
|
||||||
|
kind = b.kind,
|
||||||
|
source = tmpl.source,
|
||||||
|
path = tmpl.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Node tree
|
// Node tree
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -585,7 +601,7 @@ render_nodes :: proc(
|
|||||||
if len(node.filters) > 0 {
|
if len(node.filters) > 0 {
|
||||||
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
return perr
|
return tag_error(perr, current)
|
||||||
}
|
}
|
||||||
val = transformed
|
val = transformed
|
||||||
}
|
}
|
||||||
@@ -627,7 +643,7 @@ render_nodes :: proc(
|
|||||||
if len(node.filters) > 0 {
|
if len(node.filters) > 0 {
|
||||||
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
return perr
|
return tag_error(perr, current)
|
||||||
}
|
}
|
||||||
val = transformed
|
val = transformed
|
||||||
}
|
}
|
||||||
@@ -665,7 +681,7 @@ render_nodes :: proc(
|
|||||||
if len(node.filters) > 0 {
|
if len(node.filters) > 0 {
|
||||||
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
return perr
|
return tag_error(perr, current)
|
||||||
}
|
}
|
||||||
val = transformed
|
val = transformed
|
||||||
}
|
}
|
||||||
@@ -729,7 +745,7 @@ render_nodes :: proc(
|
|||||||
if len(node.filters) > 0 {
|
if len(node.filters) > 0 {
|
||||||
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
transformed, perr := apply_pipeline(val, node.filters[:], node.pos, ctx[:])
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
return perr
|
return tag_error(perr, current)
|
||||||
}
|
}
|
||||||
val = transformed
|
val = transformed
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user