Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use errors.Is for error comparison in assertError helper#827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tech-sam wants to merge1 commit intoquii:main
base:main
Choose a base branch
Loading
fromtech-sam:improve-error-assertion

Conversation

@tech-sam
Copy link

What problem are you trying to solve?

The currentassertError helper function in the Maps chapter uses direct error comparison (!=) which doesn't handle wrapped errors correctly. This could teach readers a pattern that might not work in real-world scenarios where error wrapping is common.

What changes are you making?

Updated theassertError helper function to useerrors.Is instead of direct comparison. This better reflects modern Go error handling practices and will work correctly with wrapped errors.

Example

Before:

if got != want {    t.Errorf("got error %q want %q", got, want)}

After:

if !errors.Is(got, want) {    t.Errorf("got error %q want %q", got, want)}

Additional context

errors.Is was introduced in Go 1.13 and is now the recommended way to compare errors. This change helps teach more robust error handling patterns.
If this change is approved, I will create a corresponding update to the README file to explain whyerrors.Is is preferred over direct comparison and provide examples of when it's particularly useful (such as with wrapped errors).

freepad and AhmadFudl reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@tech-sam

[8]ページ先頭

©2009-2025 Movatter.jp