Skip to content

doc: fix inverted wrap direction on FileNotFoundFromSearchError - #2164

Open
ump45nose wants to merge 1 commit into
spf13:masterfrom
ump45nose:fix-file-not-found-from-search-wrap-comment
Open

ump45nose wants to merge 1 commit into
spf13:masterfrom
ump45nose:fix-file-not-found-from-search-wrap-comment

Conversation

@ump45nose

Copy link
Copy Markdown

Overview:

Doc-comment-only correction on FileNotFoundFromSearchError (errors.go:36). The line reads // Wraps ConfigFileNotFoundError., which states the opposite of the actual relationship. It now reads // Wrapped by [ConfigFileNotFoundError]..

What problem does it solve?:

ConfigFileNotFoundError is the type that owns the Unwrap method, and it returns a FileNotFoundFromSearchError:

// Unwraps to FileNotFoundFromSearchError.
func (e ConfigFileNotFoundError) Unwrap() error {
	return FileNotFoundFromSearchError(e)
}

FileNotFoundFromSearchError has no Unwrap, and it is the only such method in errors.go. So ConfigFileNotFoundError is the outer error and FileNotFoundFromSearchError is the one being wrapped — the current comment inverts that, which is the kind of line a reader trusts when working out errors.Is/errors.As behaviour.

I confirmed it at runtime rather than only by reading, with a throwaway test in the package (since removed, not part of the diff):

outer=viper.ConfigFileNotFoundError unwraps to=viper.FileNotFoundFromSearchError

and errors.Unwrap(FileNotFoundFromSearchError{}) is nil.

Two notes on wording:

  • Matched the bracketed-link form already used by the neighbouring ConfigFileNotFoundError comment ([FileNotFoundFromSearchError]) so godoc renders the cross-reference.
  • This is a different line from open PR Fix "This is error wraps" doc typo on ConfigFileNotFoundError #2130, which fixes the This is error wraps grammar typo on line 19. No overlap in hunks.

Special notes for a reviewer:

No behavior change. Local checks:

  • gofmt -l . — clean
  • go vet ./... — clean
  • go test -count=1 ./... — all 5 packages ok (uncached)

ConfigFileNotFoundError has the Unwrap method (it returns
FileNotFoundFromSearchError), so FileNotFoundFromSearchError is the
wrapped error, not the wrapper. Use the bracket link form that the
neighbouring ConfigFileNotFoundError comment already uses.
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 this pull request may close these issues.

1 participant