extractPrefix extracts the prefix from a wrapper's error message. For example, err := errors.New("bar") err = errors.Wrap(err, "foo") extractPrefix(err) returns "foo". If a presumed wrapper does not have a message prefix, it is assumed to override the entire error message and `extractPrefix` r
(err, cause error)
| 195 | // the entire message and the boolean `true` to signify that the causes |
| 196 | // should not be appended to it. |
| 197 | func extractPrefix(err, cause error) (string, MessageType) { |
| 198 | causeSuffix := cause.Error() |
| 199 | errMsg := err.Error() |
| 200 | |
| 201 | if strings.HasSuffix(errMsg, causeSuffix) { |
| 202 | prefix := errMsg[:len(errMsg)-len(causeSuffix)] |
| 203 | // If error msg matches exactly then this is a wrapper |
| 204 | // with no message of its own. |
| 205 | if len(prefix) == 0 { |
| 206 | return "", Prefix |
| 207 | } |
| 208 | if strings.HasSuffix(prefix, ": ") { |
| 209 | return prefix[:len(prefix)-2], Prefix |
| 210 | } |
| 211 | } |
| 212 | // If we don't have the cause as a suffix, then we have |
| 213 | // some other string as our error msg, preserve that and |
| 214 | // mark as override |
| 215 | return errMsg, FullMessage |
| 216 | } |
| 217 | |
| 218 | func getTypeDetails( |
| 219 | err error, onlyFamily bool, |
no test coverage detected
searching dependent graphs…