-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
removed dependencies on markbates/{safe,oncer} #47
Conversation
Hi @paganotoni, please take a look at this PR and please release a new version so buffalo and other packages could import the slimmed version. Current direct dependents: |
Have you checked if the current uses of
|
Why do you think |
OK, let me reformulate my statement: it never panics unless I'm just arguing we might force users of We aren't even consistent with this: every |
Hmm, why they are comparable? The code you mentioned also has that issue: func (r *Runner) Exec(cmd *exec.Cmd) error {
r.results.Commands = append(r.results.Commands, cmd)
r.Logger.Debug("Exec: ", strings.Join(cmd.Args, " "))
<...> Referencing Again, once there are things exported, we cannot force users to not use them in their own way. |
Yes that is what I'm trying to say. If a user wants their EDIT: I found several examples in
|
Returning an error can give some chance they can do when they meet a panic situation, not always but in many cases. That is the reason the golang supports panic recovery. Why don't we allow ... to panic? because that could be safer, so the package name is Don't be serious. :-) It is better than panicking. |
No my argument has nothing to do with type MyLogger int
func (m MyLogger) Debug(...interface{}) {
// Logger panics for some reason
panic("some panic")
}
// ....
r := genny.NewRunner(context.Background())
r.Logger = MyLogger(0)
r.Exec(exec.Command("echo", "Hello", "World")) // panics because logger panics Why are we not always preventing panics? Why are we not making the call to func (r *Runner) Exec(cmd *exec.Cmd) error {
r.results.Commands = append(r.results.Commands, cmd)
if r.Logger != nil {
err := safe.Run(func() {
r.Logger.Debug("Exec: ", strings.Join(cmd.Args, " ")))
})
if err != nil {
return err
}
}
<...> The reason is quite simple: it makes our code more verbose and harder to maintain. Why should we assume that users of the Also see the code examples above. These are also places in
No; it's quite condescending to argue WE know better how to write go code than users that might use |
Note: This may be my last comment since I could not find your point anymore.
Golang supports panic since sometimes we need it, but at the same time, golang supports recovery since panic could be a real panic for users. There is no fixed way to allow them or recover them, but usually, on the deeper side like core libraries, they make panic or allow them without recovery since seeing that as-is could be better for library users/developers, but on the user-closer side, recovering the panic and making an easy-to-understand/application-specific error message could be better for end users. |
but we don't do that? We just recover the panic and return it exactly the same as error? We add no additional information or provide context. If the code panics we just assume that the panic contains a string or an error and return it as is: // Run the function safely knowing that if it panics
// the panic will be caught and returned as an error
func RunE(fn func() error) (err error) {
defer func() {
if err != nil {
return
}
if ex := recover(); ex != nil {
if e, ok := ex.(error); ok {
err = e
return
}
err = errors.New(fmt.Sprint(ex))
}
}()
return fn()
} We do nothing to help the user, we just FORCE them to use errors over panics: "because errors are better" |
Do you think this is a reasonable example?
I agree. There could be users who love panic. However, "panic or error" is the package owner's decision not the user's, and I think the reason @markbates wrote the package By the way, I feel like your sentence above is very aggressive to me, while I am telling you my opinion. :-) Maybe or I hope that is my English problem. |
Yes? We don't know who uses
Yes! We make sure OUR code doesn't panic, but not our users code. I would be very confused if my above example of a panicking logger would just return an
I don't know @markbates intention and wouldn't speculate on it. We have changed things before since Mark stopped/paused contributing to the project although Mark might have had a different plan in mind (i.e. packr/pkgr/embed)
It was not my intention to appear aggressive towards you. It is my opinion that we should let our users use our code as they wish and not tell them how they should use it :-) |
Hi @paganotoni, I and @fasmat have different opinions on this issue and I think you can make the decision on what could be better for this package. I don't think there is only one way, package owners can decide the direction with their own philosophy, opinions, or the direction of the package. I think that my PR matches buffalo's direction but if my understanding is not correct, just let me know, and please close this PR. |
I felt some aggressiveness and hope it's a language/medium thing. I encourage us to keep this conversation as friendly as possible. We are better working together and not so naive to let this Back to our original topic, I'm understanding that the discussion is about Besides that, I'm all in to reduce the amount of tiny repositories to maintain within the Buffalo organization. Safe is at the top of my list. @sio4 Please let me know if that answers the question on my oppinion. Hope it does. |
I'm not trying to attack anyone. I'm challenging "We have to safe-guard against panics" approach.
This is not a discussion of
100% agree. We are safe guarding code that is not part of
This PR would inline all usages of the |
My understanding of safeguarding in genny is simple.
This is the basic reason I think the execution should be protected. Additionally, panic recovering in Removing the safeguard could be a breaking change if there are any users who understand how it works internally and just rely on the guarantee we provided until now by recovering panic while they run a code could be panic in some situations. I will push another commit to add a warning for that change, then we can drop them later. |
Sorry that I took this much time to reply. @sio4 I think I'm im in agreement with your description for the reason of recovering. To be totally honest genny is not one of the packages I'm deeply familiarized with, but It seems like now I have some homework to do. I'm ok merging this PR. |
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.
LGTM!
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.
Thanks @sio4
@@ -6,8 +6,6 @@ require ( | |||
github.com/gobuffalo/logger v1.0.6 | |||
github.com/gobuffalo/packd v1.0.1 | |||
github.com/gobuffalo/plush/v4 v4.1.11 | |||
github.com/markbates/oncer v1.0.0 |
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.
❤️
align with gobuffalo/cli#145 and gobuffalo/buffalo#2260, removed dependencies on the following two packages:
As a note, now we have the
safe.Run
in four places:cli/internal/genny/build/validate.go
(as a form ofsafeRun()
)buffalo/worker/simple.go
(as a form ofsafeRun()
)genny/internal/safe/safe.go
(as a fullsafe.go
)events/internal/safe/safe.go
(as a fullsafe.go
)Note: a deprecated function
Runner.WithRn()
was dropped by this PR (breaking change). The function was marked as deprecated three years ago, and there is no reference to the function within the buffalo family.