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 #63621

Closed
xiaokentrl opened this issue Oct 18, 2023 · 12 comments
Closed

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

xiaokentrl opened this issue Oct 18, 2023 · 12 comments
Labels
error-handling Language & library change proposals that are about error handling. LanguageChange Suggested changes to the Go language Proposal Proposal-FinalCommentPeriod v2 An incompatible library change
Milestone

Comments

@xiaokentrl
Copy link

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

package main
 
import (
    "fmt"
    "os"
)
 
func main() {
	/*
	func demo(){
	    file, err := os.Create("example.txt") 
	    if err != nil {
	        return nil, err
	    }
	    defer file.Close()
	}
	*/

	func demo_1(){
	    file, e := os.Create("example.txt") e(nil,e)        // == return nil, err
	    defer file.Close()
	}
                          
	func demo_2(){
	    file, e(nil,e) := os.Create("example.txt")        // == return nil, err
	    defer file.Close()
	}

	func demo_3(){
	    Try
	        file, err  := os.Create("example.txt")
		defer file.Close()
	    Catch {
	        return nil, err
	    }
	}


	//file, e := os.Create("example.txt")  e(nil,err)
	//file, e := os.Create("example.txt")  e(panic)
	//file, e := os.Create("example.txt")  e("funcName")

	//file, e.panic := os.Create("example.txt")
	//file, e.call( "funcName") := os.Create("example.txt")

	//e.nil
	//e.Info
	//e.IsNumber
	
	//if ( e.nil )
	//if ( e.IsNumber )

	if dd, e := demo_1(); e.nil{
            fmt.Printf( "success dd" )
            return
	}
	fmt.Printf( "fail", e.info )
}
@xiaokentrl xiaokentrl added LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change labels Oct 18, 2023
@gopherbot gopherbot added this to the Proposal milestone Oct 18, 2023
@xiaokentrl
Copy link
Author

If the Go compiler encounters the function e( ), it automatically appends the following code on the next line:

if err != nil { 
    return nil, err
}

@ianlancetaylor ianlancetaylor added the error-handling Language & library change proposals that are about error handling. label Oct 19, 2023
@ianlancetaylor
Copy link
Contributor

I'm sorry, I don't understand the actual proposal here. What are the Try and Catch lines in demo_3?

@ianlancetaylor ianlancetaylor changed the title proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar,Hi, if you like this idea please give a heart emoji to me, Thank you very much proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar Oct 19, 2023
@thediveo
Copy link

(somehow Go2 error proposals seem to be like singing talent contests)

@cyberbeast
Copy link

cyberbeast commented Oct 19, 2023

I am not sure I understand the semantics of the proposal from the example provided. The syntactic sugar is too cryptic.

@Sniperq2
Copy link

If the Go compiler encounters the function e( ), it automatically appends the following code on the next line:

if err != nil { 
    return nil, err
}

Are you about typing lot's of boilerplate code like this? Modern IDEs already has live templates/code snippets. Also you can create you own snippets for your errors. Is this acceptable to you?

@xiaokentrl
Copy link
Author

I'm sorry, I don't understand the actual proposal here. What are the Try and Catch lines in demo_3?

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

package main
 
import (
    "fmt"
    "os"
)
 
func main() {
	/*
	func demo(){
	    file, err := os.Create("example.txt") 
	    if err != nil {
	        return nil, err
	    }
	    defer file.Close()
	}
	*/

	func demo_1(){
	    file := os.Create("example.txt").checkError( return , nil , err )
	    defer file.Close()
	}
                          
	func demo_2(){
	    file := os.Create("example.txt").checkError( panic )
	    defer file.Close()
	}

	func demo_3(){
	    file := os.Create("example.txt").checkError( return , func(){
                return 2 + 3 , nil
            })
	    defer file.Close()
	}

	if dd := demo_1(); dd.hasError {
            fmt.Printf( "dd  hasError" )
            return
	}
	fmt.Printf( "dd" )
}

@thediveo
Copy link

This example is even more confusing, I don't understand it at all. Please write down a proper proposal detailing what the syntax is and how the compiler transforms it. Thank you.

@xiaokentrl
Copy link
Author

This example is even more confusing, I don't understand it at all. Please write down a proper proposal detailing what the syntax is and how the compiler transforms it. Thank you.

Do you understand this? Thank you
#63647

@xiaokentrl
Copy link
Author

This example is even more confusing, I don't understand it at all. Please write down a proper proposal detailing what the syntax is and how the compiler transforms it. Thank you.

	func demo_1(){
	    file := os.Create("example.txt").checkError( return , nil , err )     
	    defer file.Close()
            
           //   when【 .checkError( )   】 appears,auto append    file , err := os.Create("example.txt")
           //   when【 .checkError( return , nil , err )   】 appears,auto append  if err != nil 

	}

@thediveo
Copy link

This example is even more confusing, I don't understand it at all. Please write down a proper proposal detailing what the syntax is and how the compiler transforms it. Thank you.

Do you understand this? Thank you #63647

not either, looks like a dump, but not like a fleshed-out proposal, there are good examples of issues that actually are easy to follow along and that give a concise picture. linking to the confusing issue opening itself doesn’t help.

@findleyr
Copy link
Contributor

findleyr commented Nov 1, 2023

It doesn't look like there's a concrete proposal here, and based on the emoji voting this is likely decline. Leaving open for four weeks for additional comments.

@adonovan
Copy link
Member

adonovan commented Dec 6, 2023

There were no further comments.

@adonovan adonovan closed this as completed Dec 6, 2023
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 Proposal Proposal-FinalCommentPeriod v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

8 participants