blob: 4c5c6259cb5ed5f60822b2493191d11dd798e559 [file] [log] [blame]
Serge Bazanski77628312023-02-15 23:33:22 +01001package webug
2
3import (
4 "strings"
5)
6
7var (
8 // templateFuncs are helper functions accessible to the rendered templates.
9 templateFuncs = map[string]any{
10 // summarizeError attempts to make a Go-style "foo: bar: baz" error short by
11 // using some ugly heuristics. This is currently used to show a shorter error
12 // message in the backoff column of the machine list.
13 //
14 // TODO(q3k): fix backoff causes to be less verbose and nuke this.
15 "summarizeError": func(in string) string {
16 parts := strings.Split(in, ": ")
17 for i, p := range parts {
18 // Attempt to strip some common error prefixes.
19 if strings.HasPrefix(p, "failed to ") {
20 continue
21 }
22 if strings.HasPrefix(p, "when ") {
23 continue
24 }
25 if strings.HasPrefix(p, "while ") {
26 continue
27 }
28 // If we had some prefixes stripped but suddenly reached a part that is not
29 // prefixed
30 return "[...] " + strings.Join(parts[i:], ": ")
31 }
32 // If we stripped every single segment then just return the whole thing.
33 return in
34 },
35 }
36)