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

Document named return constraint for defer #63

Merged
merged 1 commit into from Aug 12, 2022
Merged

Document named return constraint for defer #63

merged 1 commit into from Aug 12, 2022

Commits on Aug 12, 2022

  1. Document named return constraint for defer

    As discussed in #61, if you attempt to use `defer multierr.AppendInvoke`
    with an error that is not a named return, the system will lose the
    error.
    
    ```go
    func fails() error { return errors.New("great sadness") }
    
    func foo() error {
    	var err error
    	defer multierr.AppendInvoke(&err, multierr.Invoke(fails))
    	return err
    }
    
    func main() {
    	fmt.Println(foo()) // nil
    }
    ```
    
    https://go.dev/play/p/qK4NR-VYLvo
    
    This isn't something the library can address because of how defers work.
    
    This change adds a warning about the error variable being a named return
    in all places where we suggest use of multierr with defer.
    
    While we're at it, this makes use of the new `[Foo]` godoc syntax to
    generate links to other functions in the package in "See Foo"
    statements in the documentation.
    abhinav committed Aug 12, 2022
    Copy the full SHA
    a61c151 View commit details
    Browse the repository at this point in the history