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: make error handling simpler #60251

Closed
mikolajsemeniuk opened this issue May 17, 2023 · 1 comment
Closed

proposal: make error handling simpler #60251

mikolajsemeniuk opened this issue May 17, 2023 · 1 comment
Labels
error-handling Language & library change proposals that are about error handling. LanguageChange Proposal v2 A language change or incompatible library change
Milestone

Comments

@mikolajsemeniuk
Copy link

mikolajsemeniuk commented May 17, 2023

Currently when we take a look of definition of append we would see it is legal to append a string to a byte slice as a special case as documentation says:

The append built-in function appends elements to the end of a slice. If
it has sufficient capacity, the destination is resliced to accommodate the
new elements. If it does not, a new underlying array will be allocated.
Append returns the updated slice. It is therefore necessary to store the
result of append, often in the variable holding the slice itself:

	slice = append(slice, elem1, elem2)
	slice = append(slice, anotherSlice...)

As a special case, it is legal to append a string to a byte slice, like this:

	slice = append([]byte("hello "), "world"...)

I would like to have similar feature as special case for error type:

type error interface {
	Error() string
}

Instead of writing:

if err != nil {
    return err
}

We could write:

if err {
    return err
}

Which automatically check if error type is not nil and if yes execute block statement.

@gopherbot gopherbot added this to the Proposal milestone May 17, 2023
@seankhliao seankhliao added LanguageChange v2 A language change or incompatible library change error-handling Language & library change proposals that are about error handling. labels May 17, 2023
@seankhliao
Copy link
Member

Duplicate of #26712

@seankhliao seankhliao marked this as a duplicate of #26712 May 17, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 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 Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

3 participants