From e6d9ce44cf1017339b68d19cc571bf0d8a33107e Mon Sep 17 00:00:00 2001 From: Emil Koutanov Date: Sat, 18 Apr 2020 14:24:24 +1000 Subject: [PATCH] Lower-case errors --- arity/arity.go | 8 ++++---- arity/arity_test.go | 6 +++--- check/check.go | 6 +++--- check/check_test.go | 2 +- commander/commander.go | 2 +- commander/commander_test.go | 2 +- concurrent/reference_test.go | 2 +- fault/fault_test.go | 24 ++++++++++++------------ scribe/bindings_test.go | 14 +++++++------- scribe/log15/log15_binding_test.go | 4 ++-- scribe/logrus/logrus_binding_test.go | 4 ++-- scribe/mockscribe_test.go | 2 +- scribe/overlog/overlog_binding_test.go | 4 ++-- scribe/overlog/overlog_test.go | 4 ++-- scribe/scribe.go | 8 ++++---- scribe/scribe_test.go | 10 +++++----- scribe/seelog/seelog_binding_test.go | 4 ++-- scribe/zap/zap_binding_test.go | 4 ++-- 18 files changed, 55 insertions(+), 55 deletions(-) diff --git a/arity/arity.go b/arity/arity.go index c1c5966..1c1bba6 100644 --- a/arity/arity.go +++ b/arity/arity.go @@ -14,7 +14,7 @@ func Listify(array interface{}) ([]interface{}, error) { kind := reflect.TypeOf(array).Kind() if kind != reflect.Array && kind != reflect.Slice { - return nil, fmt.Errorf("Unsupported type %T", array) + return nil, fmt.Errorf("unsupported type %T", array) } value := reflect.ValueOf(array) @@ -54,8 +54,8 @@ func OptionalUntyped(offset int, limit int, def interface{}, args interface{}) i } const ( - errLimitLessThanOne = "Limit must be greater than 0" - errOffsetOutsideRange = "The limit-offset relationship must satisfy 0 <= offset < limit" + errLimitLessThanOne = "limit must be greater than 0" + errOffsetOutsideRange = "limit-offset relationship must satisfy 0 <= offset < limit" ) // Optional extracts the argument from args at the given offset if len(args) > offset, returning the specified default @@ -72,7 +72,7 @@ func Optional(offset int, limit int, def interface{}, args ...interface{}) inter length := len(args) switch { case length > limit: - panic(fmt.Errorf("Expected at most %d argument(s), got %d", limit, length)) + panic(fmt.Errorf("expected at most %d argument(s), got %d", limit, length)) case offset < length: return args[offset] default: diff --git a/arity/arity_test.go b/arity/arity_test.go index a0dd1a0..1152da3 100644 --- a/arity/arity_test.go +++ b/arity/arity_test.go @@ -18,7 +18,7 @@ func TestRepack(t *testing.T) { {[]int{0, 1, 2}, []interface{}{0, 1, 2}, nil}, {[]int{}, []interface{}{}, nil}, {[][]int{{0, 1}, {2, 3}}, []interface{}{[]int{0, 1}, []int{2, 3}}, nil}, - {4, nil, fmt.Errorf("Unsupported type int")}, + {4, nil, fmt.Errorf("unsupported type int")}, } for _, c := range cases { @@ -41,7 +41,7 @@ func TestRepackOrPanic_success(t *testing.T) { } func TestRepackOrPanic_panic(t *testing.T) { - check.ThatPanicsAsExpected(t, check.ErrorWithValue("Unsupported type int"), func() { + check.ThatPanicsAsExpected(t, check.ErrorWithValue("unsupported type int"), func() { ListifyOrPanic(0) }) } @@ -58,7 +58,7 @@ func TestSoleUntyped_oneLength(t *testing.T) { func TestSoleUntyped_tooMany(t *testing.T) { args := [...]rune{'b', 'c'} - check.ThatPanicsAsExpected(t, check.ErrorWithValue("Expected at most 1 argument(s), got 2"), func() { + check.ThatPanicsAsExpected(t, check.ErrorWithValue("expected at most 1 argument(s), got 2"), func() { SoleUntyped('a', args) }) } diff --git a/check/check.go b/check/check.go index 82a3a4c..6aed914 100644 --- a/check/check.go +++ b/check/check.go @@ -32,8 +32,8 @@ func PrintStack(depth int) string { return str.String() } -// ErrFault is a pre-canned error, useful in simulating faults. -var ErrFault = errors.New("Simulated") +// ErrSimulated is a pre-canned error, useful in simulating faults. +var ErrSimulated = errors.New("simulated") // PanicAssertion checks a given panic cause. It is used by ThatPanicsAsExpected. type PanicAssertion func(t Tester, cause interface{}) @@ -124,7 +124,7 @@ func Wait(t Tester, timeout time.Duration, interval ...time.Duration) Timesert { checkInterval := DefaultWaitCheckInterval switch { case len(interval) > 1: - panic(fmt.Errorf("Argument list too long")) + panic(fmt.Errorf("argument list too long")) case len(interval) == 1: checkInterval = interval[0] } diff --git a/check/check_test.go b/check/check_test.go index 3df23f9..5e0c715 100644 --- a/check/check_test.go +++ b/check/check_test.go @@ -146,7 +146,7 @@ func TestThatDoesNotPanic_withPanic(t *testing.T) { } func TestWait_optionalArgsTooLong(t *testing.T) { - ThatPanicsAsExpected(t, ErrorWithValue("Argument list too long"), func() { + ThatPanicsAsExpected(t, ErrorWithValue("argument list too long"), func() { Wait(t, time.Microsecond, time.Millisecond, time.Second) }) } diff --git a/commander/commander.go b/commander/commander.go index 28df610..98544a0 100644 --- a/commander/commander.go +++ b/commander/commander.go @@ -53,7 +53,7 @@ func (pm PartsMap) Value(name string, def string) (string, error) { case len(values) == 0: return def, nil default: - return values[0], fmt.Errorf("Too many arguments: expected one or none, got %d", len(values)) + return values[0], fmt.Errorf("too many arguments: expected one or none, got %d", len(values)) } } diff --git a/commander/commander_test.go b/commander/commander_test.go index 2b9cd84..ed0b818 100644 --- a/commander/commander_test.go +++ b/commander/commander_test.go @@ -94,7 +94,7 @@ func TestValue(t *testing.T) { } mapped := Parse([]string{"go", "--run", "^TestExample$", "--foo=bar", "-run=Another", "trail", "-verbose"}).Mappify() - assert.Equal(t, errors.New("Too many arguments: expected one or none, got 2"), withError(mapped.Value(FreeForm, ""))) + assert.Equal(t, errors.New("too many arguments: expected one or none, got 2"), withError(mapped.Value(FreeForm, ""))) assert.Equal(t, "bar", withoutError(mapped.Value("foo", ""))) assert.Equal(t, "true", withoutError(mapped.Value("verbose", "false"))) assert.Equal(t, "some-default", withoutError(mapped.Value("missing", "some-default"))) diff --git a/concurrent/reference_test.go b/concurrent/reference_test.go index 740a462..3fc36a4 100644 --- a/concurrent/reference_test.go +++ b/concurrent/reference_test.go @@ -60,7 +60,7 @@ func TestAtomicReference_Stringer(t *testing.T) { expectString string }{ {[]interface{}{1}, "1"}, - {[]interface{}{check.ErrFault}, "Simulated"}, + {[]interface{}{check.ErrSimulated}, "simulated"}, {[]interface{}{}, ""}, {[]interface{}{nil}, ""}, } diff --git a/fault/fault_test.go b/fault/fault_test.go index 572b571..020e22a 100644 --- a/fault/fault_test.go +++ b/fault/fault_test.go @@ -30,23 +30,23 @@ func TestZeroValue(t *testing.T) { } func TestAlways(t *testing.T) { - f := Spec{Always(), check.ErrFault}.Build() - assert.Equal(t, f.Try(), check.ErrFault) + f := Spec{Always(), check.ErrSimulated}.Build() + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 1, f.Calls()) assert.Equal(t, 1, f.Faults()) } func TestRandom_always(t *testing.T) { - f := Spec{Random(1), check.ErrFault}.Build() - assert.Equal(t, f.Try(), check.ErrFault) + f := Spec{Random(1), check.ErrSimulated}.Build() + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 1, f.Calls()) assert.Equal(t, 1, f.Faults()) } func TestRandom_sometimes(t *testing.T) { - f := Spec{Random(.1), check.ErrFault}.Build() + f := Spec{Random(.1), check.ErrSimulated}.Build() check.Wait(t, time.Second, time.Nanosecond).UntilAsserted(func(t check.Tester) { - assert.Equal(t, f.Try(), check.ErrFault) + assert.Equal(t, f.Try(), check.ErrSimulated) }) calls := f.Calls() assert.GreaterOrEqual(t, calls, 1) @@ -60,13 +60,13 @@ func TestRandom_sometimes(t *testing.T) { } func TestFirst(t *testing.T) { - f := Spec{First(2), check.ErrFault}.Build() + f := Spec{First(2), check.ErrSimulated}.Build() - assert.Equal(t, f.Try(), check.ErrFault) + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 1, f.Calls()) assert.Equal(t, 1, f.Faults()) - assert.Equal(t, f.Try(), check.ErrFault) + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 2, f.Calls()) assert.Equal(t, 2, f.Faults()) @@ -76,17 +76,17 @@ func TestFirst(t *testing.T) { } func TestAfter(t *testing.T) { - f := Spec{After(1), check.ErrFault}.Build() + f := Spec{After(1), check.ErrSimulated}.Build() assert.Nil(t, f.Try()) assert.Equal(t, 1, f.Calls()) assert.Equal(t, 0, f.Faults()) - assert.Equal(t, f.Try(), check.ErrFault) + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 2, f.Calls()) assert.Equal(t, 1, f.Faults()) - assert.Equal(t, f.Try(), check.ErrFault) + assert.Equal(t, f.Try(), check.ErrSimulated) assert.Equal(t, 3, f.Calls()) assert.Equal(t, 2, f.Faults()) } diff --git a/scribe/bindings_test.go b/scribe/bindings_test.go index d076eb1..0522f78 100644 --- a/scribe/bindings_test.go +++ b/scribe/bindings_test.go @@ -48,14 +48,14 @@ func TestAppendScene(t *testing.T) { { format: "%d %d", args: []interface{}{1, 2}, - scene: Scene{Err: check.ErrFault}, - expect: "1 2 ", + scene: Scene{Err: check.ErrSimulated}, + expect: "1 2 ", }, { format: "%d %d", args: []interface{}{1, 2}, - scene: Scene{Fields: Fields{"alpha": "bravo"}, Err: check.ErrFault}, - expect: "1 2 ", + scene: Scene{Fields: Fields{"alpha": "bravo"}, Err: check.ErrSimulated}, + expect: "1 2 ", }, } @@ -95,8 +95,8 @@ func TestShimFacs_withAppendScene(t *testing.T) { shimmed := ShimFacs(facs, AppendScene()) assert.Len(t, shimmed, 1) - shimmed[Info](Info, Scene{Err: check.ErrFault})("one %d %d", 2, 3) - assert.Equal(t, "one 2 3 ", captured) + shimmed[Info](Info, Scene{Err: check.ErrSimulated})("one %d %d", 2, 3) + assert.Equal(t, "one 2 3 ", captured) } func TestShimFac_mutateAllCallArgs(t *testing.T) { @@ -112,7 +112,7 @@ func TestShimFac_mutateAllCallArgs(t *testing.T) { } } - substituteScene := Scene{Err: check.ErrFault} + substituteScene := Scene{Err: check.ErrSimulated} shimmed := ShimFac(fac, func(level Level, scene *Scene, format *string, args *[]interface{}) { *scene = substituteScene *format = "tomarf" diff --git a/scribe/log15/log15_binding_test.go b/scribe/log15/log15_binding_test.go index c404a4f..ddd0d72 100644 --- a/scribe/log15/log15_binding_test.go +++ b/scribe/log15/log15_binding_test.go @@ -74,12 +74,12 @@ func TestWithScene_fieldsAndError(t *testing.T) { assert.NotContains(t, buffer.String(), "Err") buffer.Reset() - s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrFault}). + s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrSimulated}). I()("Charlie %d", 3) assert.Contains(t, buffer.String(), "info") assert.Contains(t, buffer.String(), "Charlie 3") assert.Contains(t, buffer.String(), "x=y") - assert.NotContains(t, buffer.String(), "Error=\"Simulated\"") + assert.NotContains(t, buffer.String(), "Error=\"simulated\"") buffer.Reset() } diff --git a/scribe/logrus/logrus_binding_test.go b/scribe/logrus/logrus_binding_test.go index f26cd60..70a906b 100644 --- a/scribe/logrus/logrus_binding_test.go +++ b/scribe/logrus/logrus_binding_test.go @@ -89,12 +89,12 @@ func TestWithScene_fieldsAndError(t *testing.T) { assert.NotContains(t, buffer.String(), "Err") buffer.Reset() - s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrFault}). + s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrSimulated}). I()("Charlie %d", 3) assert.Contains(t, buffer.String(), "level=info") assert.Contains(t, buffer.String(), "Charlie 3") assert.Contains(t, buffer.String(), "x=y") - assert.NotContains(t, buffer.String(), "Error=\"Simulated\"") + assert.NotContains(t, buffer.String(), "Error=\"simulated\"") buffer.Reset() } diff --git a/scribe/mockscribe_test.go b/scribe/mockscribe_test.go index 915c886..78029a1 100644 --- a/scribe/mockscribe_test.go +++ b/scribe/mockscribe_test.go @@ -61,7 +61,7 @@ func TestSceneLogging(t *testing.T) { testScene := func(name, value string) Scene { return Scene{ Fields: Fields{name: value}, - Err: check.ErrFault, + Err: check.ErrSimulated, } } diff --git a/scribe/overlog/overlog_binding_test.go b/scribe/overlog/overlog_binding_test.go index 0b23783..d02a4af 100644 --- a/scribe/overlog/overlog_binding_test.go +++ b/scribe/overlog/overlog_binding_test.go @@ -34,8 +34,8 @@ func TestLogLevels(t *testing.T) { Fields: scribe.Fields{ "foo": "bar", }, - Err: check.ErrFault}). + Err: check.ErrSimulated}). E()("Echo %d", 5) - assert.Contains(t, buffer.String(), "ERR Echo 5 ") + assert.Contains(t, buffer.String(), "ERR Echo 5 ") buffer.Reset() } diff --git a/scribe/overlog/overlog_test.go b/scribe/overlog/overlog_test.go index c6a90c3..52a920e 100644 --- a/scribe/overlog/overlog_test.go +++ b/scribe/overlog/overlog_test.go @@ -96,8 +96,8 @@ func TestLevel(t *testing.T) { func TestScene(t *testing.T) { b := &bytes.Buffer{} s := New(Scene(), b) - s.With(scribe.Info, scribe.Scene{Fields: scribe.Fields{"foo": "bar"}, Err: check.ErrFault})("irrelevant") - assert.Equal(t, " \n", b.String()) + s.With(scribe.Info, scribe.Scene{Fields: scribe.Fields{"foo": "bar"}, Err: check.ErrSimulated})("irrelevant") + assert.Equal(t, " \n", b.String()) } func TestFormat(t *testing.T) { diff --git a/scribe/scribe.go b/scribe/scribe.go index 7098c0b..ded8b9a 100644 --- a/scribe/scribe.go +++ b/scribe/scribe.go @@ -92,7 +92,7 @@ func (l Level) String() string { } func noLevelForOrdinal(level Level) (string, error) { - return fmt.Sprintf("", level), fmt.Errorf("No level for ordinal %d", level) + return fmt.Sprintf("", level), fmt.Errorf("no level for ordinal %d", level) } // LevelName gets the name of the given level, if one is known. An error is returned if the level is not among the @@ -120,7 +120,7 @@ func ParseLevelName(name string) (LevelSpec, error) { return spec, nil } } - return LevelSpec{}, fmt.Errorf("No level specification for name '%s'", name) + return LevelSpec{}, fmt.Errorf("no level specification for name '%s'", name) } // Fields is a free-form set of attributes that can be captured as part of a Scene, supporting @@ -229,7 +229,7 @@ func New(facs LoggerFactories) Scribe { } if _, ok := expandedFacs[l.Level]; !ok { if defFac == nil { - panic(fmt.Errorf("Missing logger factory for level %s; no default has been provided", l.Name)) + panic(fmt.Errorf("missing logger factory for level %s; no default has been provided", l.Name)) } expandedFacs[l.Level] = defFac } @@ -289,7 +289,7 @@ func (s *scribe) fac(level Level) LoggerFactory { } // An invalid level was supplied - panic(fmt.Errorf("Missing logger factory for level %s", level.String())) + panic(fmt.Errorf("missing logger factory for level %s", level.String())) } func (ss *sceneStub) L(level Level) Logger { diff --git a/scribe/scribe_test.go b/scribe/scribe_test.go index bad943a..9a659bb 100644 --- a/scribe/scribe_test.go +++ b/scribe/scribe_test.go @@ -51,7 +51,7 @@ func TestParseLevelName(t *testing.T) { {in: "All", wantSpec: Levels[All], wantError: ""}, {in: "Trace", wantSpec: Levels[Trace], wantError: ""}, {in: "Off", wantSpec: Levels[Off], wantError: ""}, - {in: "Foo", wantSpec: LevelSpec{}, wantError: "No level specification for name 'Foo'"}, + {in: "Foo", wantSpec: LevelSpec{}, wantError: "no level specification for name 'Foo'"}, } for _, c := range cases { @@ -170,14 +170,14 @@ func assertNoCaptures(t *testing.T, captures ...logCapture) { func TestMissingLevel(t *testing.T) { l := New(LoggerFactories{All: nopFac}) - check.ThatPanicsAsExpected(t, check.ErrorWithValue("Missing logger factory for level "), func() { + check.ThatPanicsAsExpected(t, check.ErrorWithValue("missing logger factory for level "), func() { logger := l.L(80) t.Log(logger) }) } func TestInitWithoutDefault(t *testing.T) { - check.ThatPanicsAsExpected(t, check.ErrorWithValue("Missing logger factory for level Trace; no default has been provided"), func() { + check.ThatPanicsAsExpected(t, check.ErrorWithValue("missing logger factory for level Trace; no default has been provided"), func() { New(LoggerFactories{ Debug: nopFac, Info: nopFac, @@ -186,7 +186,7 @@ func TestInitWithoutDefault(t *testing.T) { }) }) - check.ThatPanicsAsExpected(t, check.ErrorWithValue("Missing logger factory for level Error; no default has been provided"), func() { + check.ThatPanicsAsExpected(t, check.ErrorWithValue("missing logger factory for level Error; no default has been provided"), func() { New(LoggerFactories{ Trace: nopFac, Debug: nopFac, @@ -208,7 +208,7 @@ func TestName(t *testing.T) { {Info, "Info", nil}, {Warn, "Warn", nil}, {Error, "Error", nil}, - {11, "", fmt.Errorf("No level for ordinal 11")}, + {11, "", fmt.Errorf("no level for ordinal 11")}, } for _, c := range cases { diff --git a/scribe/seelog/seelog_binding_test.go b/scribe/seelog/seelog_binding_test.go index 03a8d82..e4e8c9d 100644 --- a/scribe/seelog/seelog_binding_test.go +++ b/scribe/seelog/seelog_binding_test.go @@ -78,9 +78,9 @@ func TestWithScene(t *testing.T) { assert.NotContains(t, buffer.String(), "Err") buffer.Reset() - s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrFault}). + s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrSimulated}). I()("Charlie %d", 3) assert.Contains(t, buffer.String(), "INF") - assert.Contains(t, buffer.String(), "Charlie 3 ") + assert.Contains(t, buffer.String(), "Charlie 3 ") buffer.Reset() } diff --git a/scribe/zap/zap_binding_test.go b/scribe/zap/zap_binding_test.go index 8cf4e35..c7c465f 100644 --- a/scribe/zap/zap_binding_test.go +++ b/scribe/zap/zap_binding_test.go @@ -76,11 +76,11 @@ func TestWithScene(t *testing.T) { assert.NotContains(t, buffer.String(), "Err") buffer.Reset() - s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrFault}). + s.Capture(scribe.Scene{Fields: scribe.Fields{"x": "y"}, Err: check.ErrSimulated}). I()("Charlie %d", 3) assert.Contains(t, buffer.String(), "INF") assert.Contains(t, buffer.String(), `"x": "y"`) - assert.Contains(t, buffer.String(), `"Err": "Simulated"`) + assert.Contains(t, buffer.String(), `"Err": "simulated"`) assert.Contains(t, buffer.String(), "Charlie 3") buffer.Reset() }