(err error, trace []runtime.Frame, path []int)
| 110 | } |
| 111 | |
| 112 | func (p *treeWriter) writeTrace(err error, trace []runtime.Frame, path []int) { |
| 113 | // A trace for a single error takes |
| 114 | // the same form as a stack trace: |
| 115 | // |
| 116 | // error message |
| 117 | // |
| 118 | // func1 |
| 119 | // path/to/file.go:12 |
| 120 | // func2 |
| 121 | // path/to/file.go:34 |
| 122 | // |
| 123 | // However, when path isn't empty, we're part of a tree, |
| 124 | // so we need to add prefixes containers around the trace |
| 125 | // to indicate the tree structure. |
| 126 | // |
| 127 | // We print in depth-first order, so we get: |
| 128 | // |
| 129 | // +- error message 1 |
| 130 | // | |
| 131 | // | func5 |
| 132 | // | path/to/file.go:90 |
| 133 | // | func6 |
| 134 | // | path/to/file.go:12 |
| 135 | // | |
| 136 | // +- error message 2 |
| 137 | // | |
| 138 | // | func7 |
| 139 | // | path/to/file.go:34 |
| 140 | // | func8 |
| 141 | // | path/to/file.go:56 |
| 142 | // | |
| 143 | // +- error message 3 |
| 144 | // | |
| 145 | // | func3 |
| 146 | // | path/to/file.go:57 |
| 147 | // | func4 |
| 148 | // | path/to/file.go:78 |
| 149 | // | |
| 150 | // error message 4 |
| 151 | // |
| 152 | // func1 |
| 153 | // path/to/file.go:12 |
| 154 | // func2 |
| 155 | // path/to/file.go:34 |
| 156 | |
| 157 | // +- error message |
| 158 | // | |
| 159 | // |
| 160 | // The message may have newlines in it, |
| 161 | // so we need to print each line separately. |
| 162 | for i, line := range strings.Split(err.Error(), "\n") { |
| 163 | if i == 0 { |
| 164 | p.pipes(path, "+- ") |
| 165 | } else { |
| 166 | p.pipes(path, "| ") |
| 167 | } |
| 168 | p.writeString(line) |
| 169 | p.writeString("\n") |
no test coverage detected