package fixture import "fmt" // Not compiled. Each sentence has text of its own, and a row with a // would match it, but the placeholder carries an error's text. type refusal struct{} func (refusal) Error() string { return "refused" } type result struct{ Err error } // MV-N2's format with the error as its list. func formatArg(w int, to string, err error) { jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %v", to, err)) } func concatError(w int, err error) { jsonError(w, 400, "the region refused it: "+err.Error()) } // A %w argument is an error whatever its declared type. func wrapVerb(w int, to string, why string) { jsonError(w, 400, fmt.Sprintf("region %s failed: %w", to, why)) } // A value of a type that implements error. func implementsError(w int, r refusal) { jsonError(w, 400, fmt.Sprintf("the region refused: %v", r)) } // An identifier the gate cannot type, named like an error. func unknownErr(w int) { jsonError(w, 400, fmt.Sprintf("the last attempt failed: %v", lastErr)) } // A field whose declared type is error. func errorField(w int, res result) { jsonError(w, 400, fmt.Sprintf("the copy failed: %s", res.Err)) } // A local that holds an error's text. func localText(w int, err error) { detail := err.Error() jsonError(w, 400, "the copy failed: "+detail) } // A helper whose string parameter is bound to an error's text. func viaHelper(w int, err error) { jsonError(w, 400, explain(fmt.Sprint(err))) } func explain(m string) string { return "the copy failed: " + m }