MCPcopy Index your code
hub / github.com/cockroachdb/errors / extractPrefix

Function extractPrefix

errbase/encode.go:197–216  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

195// the entire message and the boolean `true` to signify that the causes
196// should not be appended to it.
197func 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
218func getTypeDetails(
219 err error, onlyFamily bool,

Callers 2

formatSimpleMethod · 0.85
encodeWrapperFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…