| 316 | } |
| 317 | |
| 318 | func cleanupParseError(filename string, err error) error { |
| 319 | tokens := strings.Split(err.Error(), ": ") |
| 320 | if len(tokens) == 1 { |
| 321 | // This might happen if a non-templating error occurs |
| 322 | return fmt.Errorf("parse error in (%s): %w", filename, err) |
| 323 | } |
| 324 | // The first token is "template" |
| 325 | // The second token is either "filename:lineno" or "filename:lineNo:columnNo" |
| 326 | location := tokens[1] |
| 327 | // The remaining tokens make up a stacktrace-like chain, ending with the relevant error |
| 328 | errMsg := tokens[len(tokens)-1] |
| 329 | return fmt.Errorf("parse error at (%s): %s", location, errMsg) |
| 330 | } |
| 331 | |
| 332 | type TraceableError struct { |
| 333 | location string |