Skip to content

Commit

Permalink
Lower-case errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Apr 18, 2020
1 parent a8b24e8 commit e6d9ce4
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions arity/arity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions arity/arity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
})
}
Expand All @@ -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)
})
}
Expand Down
6 changes: 3 additions & 3 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion commander/commander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
2 changes: 1 addition & 1 deletion concurrent/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestAtomicReference_Stringer(t *testing.T) {
expectString string
}{
{[]interface{}{1}, "1"},
{[]interface{}{check.ErrFault}, "Simulated"},
{[]interface{}{check.ErrSimulated}, "simulated"},
{[]interface{}{}, "<nil>"},
{[]interface{}{nil}, "<nil>"},
}
Expand Down
24 changes: 12 additions & 12 deletions fault/fault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())

Expand All @@ -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())
}
14 changes: 7 additions & 7 deletions scribe/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func TestAppendScene(t *testing.T) {
{
format: "%d %d",
args: []interface{}{1, 2},
scene: Scene{Err: check.ErrFault},
expect: "1 2 <Simulated>",
scene: Scene{Err: check.ErrSimulated},
expect: "1 2 <simulated>",
},
{
format: "%d %d",
args: []interface{}{1, 2},
scene: Scene{Fields: Fields{"alpha": "bravo"}, Err: check.ErrFault},
expect: "1 2 <alpha:bravo> <Simulated>",
scene: Scene{Fields: Fields{"alpha": "bravo"}, Err: check.ErrSimulated},
expect: "1 2 <alpha:bravo> <simulated>",
},
}

Expand Down Expand Up @@ -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 <Simulated>", captured)
shimmed[Info](Info, Scene{Err: check.ErrSimulated})("one %d %d", 2, 3)
assert.Equal(t, "one 2 3 <simulated>", captured)
}

func TestShimFac_mutateAllCallArgs(t *testing.T) {
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions scribe/log15/log15_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions scribe/logrus/logrus_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion scribe/mockscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
4 changes: 2 additions & 2 deletions scribe/overlog/overlog_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <foo:bar> <Simulated>")
assert.Contains(t, buffer.String(), "ERR Echo 5 <foo:bar> <simulated>")
buffer.Reset()
}
4 changes: 2 additions & 2 deletions scribe/overlog/overlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<foo:bar> <Simulated>\n", b.String())
s.With(scribe.Info, scribe.Scene{Fields: scribe.Fields{"foo": "bar"}, Err: check.ErrSimulated})("irrelevant")
assert.Equal(t, "<foo:bar> <simulated>\n", b.String())
}

func TestFormat(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions scribe/scribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (l Level) String() string {
}

func noLevelForOrdinal(level Level) (string, error) {
return fmt.Sprintf("<ordinal %d>", level), fmt.Errorf("No level for ordinal %d", level)
return fmt.Sprintf("<ordinal %d>", 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions scribe/scribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 <ordinal 80>"), func() {
check.ThatPanicsAsExpected(t, check.ErrorWithValue("missing logger factory for level <ordinal 80>"), 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,
Expand All @@ -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,
Expand All @@ -208,7 +208,7 @@ func TestName(t *testing.T) {
{Info, "Info", nil},
{Warn, "Warn", nil},
{Error, "Error", nil},
{11, "<ordinal 11>", fmt.Errorf("No level for ordinal 11")},
{11, "<ordinal 11>", fmt.Errorf("no level for ordinal 11")},
}

for _, c := range cases {
Expand Down
4 changes: 2 additions & 2 deletions scribe/seelog/seelog_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <x:y> <Simulated>")
assert.Contains(t, buffer.String(), "Charlie 3 <x:y> <simulated>")
buffer.Reset()
}
4 changes: 2 additions & 2 deletions scribe/zap/zap_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit e6d9ce4

Please sign in to comment.