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