MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ToDisplayString

Method ToDisplayString

common/error.go:46–74  ·  view source on GitHub ↗

ToDisplayString decorates the error message with the source location.

(source Source)

Source from the content-addressed store, hash-verified

44
45// ToDisplayString decorates the error message with the source location.
46func (e *Error) ToDisplayString(source Source) string {
47 var result = fmt.Sprintf("ERROR: %s:%d:%d: %s",
48 source.Description(),
49 e.Location.Line(),
50 e.Location.Column()+1, // add one to the 0-based column for display
51 e.Message)
52 if snippet, found := source.Snippet(e.Location.Line()); found && len(snippet) <= maxSnippetLength {
53 snippet := strings.Replace(snippet, "\t", " ", -1)
54 srcLine := "\n | " + snippet
55 var bytes = []byte(snippet)
56 var indLine = "\n | "
57 for i := 0; i < e.Location.Column() && len(bytes) > 0; i++ {
58 _, sz := utf8.DecodeRune(bytes)
59 bytes = bytes[sz:]
60 if sz > 1 {
61 indLine += wideDot
62 } else {
63 indLine += dot
64 }
65 }
66 if _, sz := utf8.DecodeRune(bytes); sz > 1 {
67 indLine += wideInd
68 } else {
69 indLine += ind
70 }
71 result += srcLine + indLine
72 }
73 return result
74}

Callers 15

TestPruneFunction · 0.45
programFunction · 0.45
testMustParseFunction · 0.45
TestCheckFunction · 0.45
BenchmarkCheckFunction · 0.45
TestCheckErrorDataFunction · 0.45

Calls 4

DescriptionMethod · 0.65
LineMethod · 0.65
ColumnMethod · 0.65
SnippetMethod · 0.65

Tested by 15

TestPruneFunction · 0.36
programFunction · 0.36
testMustParseFunction · 0.36
TestCheckFunction · 0.36
BenchmarkCheckFunction · 0.36
TestCheckErrorDataFunction · 0.36