Closed
Description
Feature Description
Example: help more problems like #24118
Before
count, err := actions_model.CountRunners(ctx, opts)
if err != nil {
ctx.ServerError("AdminRunners", err)
return
}
There are some problems:
- The function names changes during refactoring, so the ServerError frequently gets out-of-sync.
- People have to copy&paste duplicate code again and again.
- The
return
could be forgotten, a lot of times.
Proposal 1
Use generic, let a function like ErrorProof
handles server errors automatically.
ErrorProof
can use reflect to get the target function's name, it doesn't affect performance because in most cases there is no "internal server error".
count, err := ctx.ErrorProof(actions_model.CountRunners, ctx, opts))
if err != nil {
return
}
Proposal 2
Return the err directly, make our handler framework support such return value for handler functions (with stacktrace):
count, err := actions_model.CountRunners(ctx, opts)
if err != nil {
return ctx.ErrorWithStack(err)
}
Feasible?
These are just some early ideas, haven't tried whether it is really feasible, but if people like this proposal, I will spend some time to try.
I really prefer the second one, it looks clear and intuitive