prefer NoError/Error over Nil/NotNil #12271

Merged
trashhalo merged 1 commits from prefer-error into master 2020-07-19 09:53:41 +00:00
trashhalo commented 2020-07-19 01:09:55 +00:00 (Migrated from github.com)

replaces calls to require/assert Nil/NotNil to NoError/Error

NoError is for asserting no error was return
Error is for asserting an error was returned

Why is it important?

return Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err), msgAndArgs...)
return Fail(t, "An error is expected but got nil.", msgAndArgs...)

When these fail their message explicitly calls out that we were or were not expecting an error. This communicates the intent of the assertion.

replaces calls to require/assert Nil/NotNil to NoError/Error [NoError](https://godoc.org/github.com/stretchr/testify/require#NoError) is for asserting no error was return [Error](https://godoc.org/github.com/stretchr/testify/require#Error) is for asserting an error was returned ## Why is it important? ```golang return Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err), msgAndArgs...) ``` ```golang return Fail(t, "An error is expected but got nil.", msgAndArgs...) ``` When these fail their message explicitly calls out that we were or were not expecting an error. This communicates the intent of the assertion.
lunny approved these changes 2020-07-19 02:10:41 +00:00
lafriks (Migrated from github.com) approved these changes 2020-07-19 09:53:17 +00:00
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/gitea#12271
No description provided.