carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package fixture
2
3import "fmt"
4
5// Not compiled. Each sentence has text of its own, and a row with a
6// <placeholder> would match it, but the placeholder carries an error's text.
7
8type refusal struct{}
9
10func (refusal) Error() string { return "refused" }
11
12type result struct{ Err error }
13
14// MV-N2's format with the error as its list.
15func formatArg(w int, to string, err error) {
16 jsonError(w, 400, fmt.Sprintf("region %s is not one of this app's regions: %v", to, err))
17}
18
19func concatError(w int, err error) {
20 jsonError(w, 400, "the region refused it: "+err.Error())
21}
22
23// A %w argument is an error whatever its declared type.
24func wrapVerb(w int, to string, why string) {
25 jsonError(w, 400, fmt.Sprintf("region %s failed: %w", to, why))
26}
27
28// A value of a type that implements error.
29func implementsError(w int, r refusal) {
30 jsonError(w, 400, fmt.Sprintf("the region refused: %v", r))
31}
32
33// An identifier the gate cannot type, named like an error.
34func unknownErr(w int) {
35 jsonError(w, 400, fmt.Sprintf("the last attempt failed: %v", lastErr))
36}
37
38// A field whose declared type is error.
39func errorField(w int, res result) {
40 jsonError(w, 400, fmt.Sprintf("the copy failed: %s", res.Err))
41}
42
43// A local that holds an error's text.
44func localText(w int, err error) {
45 detail := err.Error()
46 jsonError(w, 400, "the copy failed: "+detail)
47}
48
49// A helper whose string parameter is bound to an error's text.
50func viaHelper(w int, err error) {
51 jsonError(w, 400, explain(fmt.Sprint(err)))
52}
53
54func explain(m string) string {
55 return "the copy failed: " + m
56}
57