Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array and slice naming assumption #42

Closed
maraino opened this issue Jul 9, 2024 · 2 comments · Fixed by #47
Closed

Array and slice naming assumption #42

maraino opened this issue Jul 9, 2024 · 2 comments · Fixed by #47

Comments

@maraino
Copy link

maraino commented Jul 9, 2024

Why is there an assumption of using the XxxErrors format for an array or slice? In many cases, it makes more sense to name them XxxError, for example:

package flagutil

type IncompatiblePairError [2]string

func (e IncompatiblePairError) Error() string {
	return fmt.Sprintf("flag --%s is incompatible with --%s", e[0], e[1])
}

This will fail with:

.../flagutil/flagutil.go: the type name `IncompatiblePairError` should conform to the `XxxErrors` format

It clearly does not represent multiple errors. Since many examples can be created with a slice or an array, why not allow both?

@Antonboom
Copy link
Owner

Antonboom commented Oct 4, 2024

Hello, @maraino

It was introduced in #3

But I found that both options are widely used

  1. https://github.com/search?q=%2Ftype.*Errors+%5C%5B%2F+language%3AGo+&type=code
  2. https://github.com/search?q=%2Ftype.*Error+%5C%5B%2F+language%3AGo+&type=code

So it looks reasonable to reconsider this decision 👍

@Antonboom
Copy link
Owner

After fix:

$ errname util.go
/tmp/sandbox/util.go:5:6: the error type name `IncompatiblePairEror` should conform to the `XxxErrors` or `XxxError` format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants