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

proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar #63961

Closed
xiaokentrl opened this issue Nov 6, 2023 · 4 comments
Closed

proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar #63961

xiaokentrl opened this issue Nov 6, 2023 · 4 comments
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@xiaokentrl
Copy link

xiaokentrl commented Nov 6, 2023

Hi, if you like this idea please give a heart emoji to me, Thank you very much

func copy(src, dst string) (int64, error) {

    r, err := os.Open("input.txt")
    if err != nil {
        return 0, err
    }
    defer r.Close()
 
    w, err := os.Create("output.txt")
    if err != nil {
        return 0, err
    }
    defer w.Close()
    
    if _, err = io.Copy(w, r); err != nil {
        return 0, err
    }
    return 0, err
}

Add keywords listen:

listen: err {
    if err != nil  {
        return 0, err
    }
    return 0, nil
}()

func copy(src, dst string) (int64, error) {
    listen:
    
    r, err := os.Open("input.txt")
    defer r.Close()
 
    w, err := os.Create("output.txt")
    defer w.Close()

    _, err = io.Copy(w, r) 
}
@xiaokentrl xiaokentrl added LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change labels Nov 6, 2023
@gopherbot gopherbot added this to the Proposal milestone Nov 6, 2023
@xiaokentrl
Copy link
Author

xiaokentrl commented Nov 6, 2023

listen: err | err2 {
    if err != nil  {
        return 0, err
    }
    return 0, nil
}()

func copy(src, dst string) (int64, error) {
    listen:  
    
    r, err := os.Open("input.txt")
    defer r.Close()
 
    w, err := os.Create("output.txt")
    defer w.Close()

    _, err = io.Copy(w, r) 
}

@seankhliao
Copy link
Member

Please fill out https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing language changes

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 6, 2023
@mpldr
Copy link
Contributor

mpldr commented Nov 6, 2023

I have to admit, I am a bit stumped by the syntax… is this basically a label outside the function? What is err2? What is the proposed functionality exactly. Why does the listen "label-function" not have any parameters? why does your example return 0 and not the bytecount of copy? So many questions!

@seankhliao seankhliao added the error-handling Language & library change proposals that are about error handling. label Nov 17, 2023
@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
@golang golang locked and limited conversation to collaborators Dec 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants