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: spec: error handling with || return err #68146

Closed
pwtitle opened this issue Jun 24, 2024 · 10 comments
Closed

proposal: spec: error handling with || return err #68146

pwtitle opened this issue Jun 24, 2024 · 10 comments
Labels
error-handling Language & library change proposals that are about error handling. LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal Proposal-FinalCommentPeriod
Milestone

Comments

@pwtitle
Copy link

pwtitle commented Jun 24, 2024

Proposal Details

I have a new error return proposal:

  1. very simple, very golang, very short
  2. does not add new Keyword or Operators
  3. good compatibility
  4. not changing the error way

** For examples: **

image
@gopherbot gopherbot added this to the Proposal milestone Jun 24, 2024
@pwtitle
Copy link
Author

pwtitle commented Jun 24, 2024

i like it, do you like it?

@ianlancetaylor
Copy link
Contributor

Looks at lot like #21161.

@ianlancetaylor ianlancetaylor added v2 An incompatible library change error-handling Language & library change proposals that are about error handling. LanguageChange Suggested changes to the Go language labels Jun 24, 2024
@seankhliao seankhliao changed the title proposal: error: a new error return proposal proposal: Go 2: error handling with || return err Jun 24, 2024
@ruyi789
Copy link

ruyi789 commented Jun 24, 2024

func test1() (b []byte,err error ){
	b, err = os.ReadFile("./test1")
	//if-simplify
	if l:=len(b);l==0||l>65536@nil,fmt.Errorf("bad data:%d",l)
	else b==[]byte("bad")@nil,fmt.Errorf("bad file:%d",l)
	else if err==io.ErrUnexpectedEOF{
		//fmt.Println(string(b))
		//panic(fmt.Errorf("ErrUnexpectedEOF:%d",l))
                return nil,err
	}
	else b,err==io.EOF@nil
	else nil,err!
    return b,nil 
}


@ianlancetaylor
Copy link
Contributor

@ruyi789 That looks like a completely different idea that should be discussed on a different issue. Thanks.

@leaxoy

This comment was marked as off-topic.

@Z3NTL3
Copy link

Z3NTL3 commented Jun 27, 2024

Eyyo Rust's approach is very good and Zig's too. Very convenient, simple, elegant and compact. We need some improvement around this.

Can someone of the Go team please inform us about how far we are for a decision on how to improve this for the sake of Go.
By the way I do not like the error handling in this proposal, dont think so anyone does, again too verbose.

@pwtitle
Copy link
Author

pwtitle commented Jul 5, 2024

verbose?

|| return

verbose???

@ianlancetaylor ianlancetaylor changed the title proposal: Go 2: error handling with || return err proposal: spec: error handling with || return err Aug 6, 2024
@ianlancetaylor ianlancetaylor added LanguageChangeReview Discussed by language change review committee and removed v2 An incompatible library change labels Aug 6, 2024
@ianlancetaylor
Copy link
Contributor

This is very similar to #61750 and the recent #67955, with a slightly different syntax. It's syntactically unlike anything else in Go, with a return not in a block. The emoji voting is not in favor. Therefore, this is a likely decline. Leaving open for four weeks for final comments.

@ianlancetaylor
Copy link
Contributor

No further comments.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-handling Language & library change proposals that are about error handling. LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal Proposal-FinalCommentPeriod
Projects
None yet
Development

No branches or pull requests

7 participants