-
Notifications
You must be signed in to change notification settings - Fork 383
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
feat(p/ufmt): add ufmt.Errorf #1767
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
the
🧾 package/realm
Tag used for new Realms or Packages.
label
Mar 13, 2024
leohhhn
approved these changes
Mar 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks 🙏
Please just fix the red CI :)
thehowl
approved these changes
Mar 13, 2024
thehowl
changed the title
feat(gno.land): add ufmt.Errorf
feat(p/ufmt): add ufmt.Errorf
Mar 13, 2024
thehowl
reviewed
Mar 13, 2024
albttx
pushed a commit
to albttx/gno
that referenced
this pull request
Mar 15, 2024
# Description Added the `Errorf` function to `ufmt` based on `ufmt.Sprintf`. Previously, formatting errors involved a method like using `errors.New(ufmt.Sprintf(XXX))`, but this approach is not only cumbersome but also, as using `Errorf` is recommended in Go, I have newly incorporated it. ## Usage ### Simple Error This example demonstrates the process of using `Errorf` to format and print error messages. ```go package main import ( "gno.land/p/demo/ufmt" ) func foo() error { return fmt.Errorf("an error occurred in simpleFunction") } func main() { if err := foo(); err != nil { println("Error:", err) } } ``` ### With Panic Using panic is the recommended practice in [effective gno](<https://docs.gno.land/concepts/effective-gno/#embrace-panic>), In this example, format the error and then output the error message with `panic`. ```go package main import ( "gno.land/p/demo/ufmt" ) func foo() { msg := ufmt.Errorf("error: %s", "something went wrong") panic(msg) } ``` --------- Co-authored-by: Morgan <[email protected]>
albttx
pushed a commit
to albttx/gno
that referenced
this pull request
Mar 15, 2024
…rorf` (gnolang#1772) ## Description Replace previouse formatted error creations with `fmt.Errof` (in gno, `ufmt.Errorf`) to simplify error creation and formatting. Follow up for PR gnolang#1767
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Added the
Errorf
function toufmt
based onufmt.Sprintf
.Previously, formatting errors involved a method like using
errors.New(ufmt.Sprintf(XXX))
, but this approach is not only cumbersome but also, as usingErrorf
is recommended in Go, I have newly incorporated it.Usage
Simple Error
This example demonstrates the process of using
Errorf
to format and print error messages.With Panic
Using panic is the recommended practice in effective gno, In this example, format the error and then output the error message with
panic
.