| 1 | package fixture |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | // Not compiled. MV-N2's format, with its list made by a package helper or |
| 6 | // read from a string field. Each carries an error's text, or text the gate |
| 7 | // cannot derive, and no row vouches for that. |
| 8 | |
| 9 | func detail(err error) string { |
| 10 | return err.Error() |
| 11 | } |
| 12 | |
| 13 | func viaHelper(w int, to string, err error) { |
| 14 | jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %s", to, detail(err))) |
| 15 | } |
| 16 | |
| 17 | func viaHelperConcat(w int, to string, err error) { |
| 18 | jsonError(w, 400, "region "+to+" is not one of this app's regions: "+detail(err)) |
| 19 | } |
| 20 | |
| 21 | // A helper whose return the gate cannot derive: the receiver is shadowed, so |
| 22 | // the gate cannot tell which describe runs. |
| 23 | type local struct{} |
| 24 | |
| 25 | func (local) describe() string { return "a recorded sentence" } |
| 26 | |
| 27 | func opaque(x local, y thing) string { |
| 28 | if x := y; x != nil { |
| 29 | return x.describe() |
| 30 | } |
| 31 | return "a recorded sentence" |
| 32 | } |
| 33 | |
| 34 | func viaOpaque(w int, to string, x local, y thing) { |
| 35 | jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %s", to, opaque(x, y))) |
| 36 | } |
| 37 | |
| 38 | // A helper that returns its parameter, bound to an error's text. |
| 39 | func echo(m string) string { |
| 40 | return m |
| 41 | } |
| 42 | |
| 43 | func viaEcho(w int, to string, err error) { |
| 44 | jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %s", to, echo(fmt.Sprint(err)))) |
| 45 | } |
| 46 | |
| 47 | // A string field written from an error's text. |
| 48 | type failure struct{ Detail string } |
| 49 | |
| 50 | func record(err error) failure { |
| 51 | return failure{Detail: err.Error()} |
| 52 | } |
| 53 | |
| 54 | func viaField(w int, to string, f failure) { |
| 55 | jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %s", to, f.Detail)) |
| 56 | } |
| 57 | |
| 58 | func viaFieldConcat(w int, to string, f failure) { |
| 59 | jsonError(w, 400, "region "+to+" is not one of this app's regions: "+f.Detail) |
| 60 | } |
| 61 | |