-
Notifications
You must be signed in to change notification settings - Fork 55
CreateNamespace: do not hide error from lower call #116
Conversation
pkg/ndctl/ndctl.go
Outdated
@@ -66,6 +66,8 @@ func (ctx *Context) CreateNamespace(opts CreateNamespaceOpts) (*Namespace, error | |||
for _, r := range bus.ActiveRegions() { | |||
if ns, err := r.CreateNamespace(opts); err == nil { | |||
return ns, nil | |||
} else { | |||
return nil, err |
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.
As of i remember, it was intentional, to try with all available regions to serve the creation request. If upper layers are interested in error would call Region.CreateNamespace().
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.
As @avalluri pointed out, this changes the semantic.
Otherwise a shorter way to write this if/else would be
return r.CreateNamespace(opts)
.
But even better is to wrap errors with errors.Wrap
from https://github.com/pkg/errors because then additional information and a stack trace gets added at each level.
gRPC logging however currently doesn't show the stack trace, so that part isn't useful at the moment.
6a49330
to
27ddb0d
Compare
Thanks for Wrap idea, it really seems good solution for multiple/nested errors case. I force-pushed change to use Wrap, fixes the issue without changing semantics.
The current code produces this message in case of one Region:
extra colon mark(s) seems result of Wrap() with empty string, but this is just cosmetic problem |
27ddb0d
to
3f41ab0
Compare
another minor thing, should we use import() block instead of multiple import statements |
ee35751
to
2f8600b
Compare
I tried this on a system with 6 Regions were same error happens, and contrary to my expectation (to see 6 times same message repeated) there is just single one:
Does error.Wrap avoid repeating same msg? or is there something wrong with how Wrap is used here. |
what about instead creating more complex error msg manipulation and analyzing there, we just log errors after we get them from lower/layer call, and we return single (new) error, as it was originally. Thats actually much simpler than wrap/analyze. The potential issue with that will be, list of per-Region errors is not returned via RPC but written in log instead. But it's still better than original state where error was not shown at all. |
Olev Kartau <[email protected]> writes:
what about instead creating more complex error msg manipulation and
analyzing there, we just log errors after we get them from lower/layer
call, and we return single (new) error, as it was originally. Thats
actually much simpler than wrap/analyze. The potential issue with that
will be, list of per-Region errors is not returned via RPC but written
in log instead. But it's still better than original state where error
was not shown at all.
How easily can the error be discovered in the log?
This probably needs to go into an "admin cookbook" section in the
README.md.
|
k8s log info in general is not easy to discover IMHO, but if msg is logged, it can be retrieved, easy or less easy. |
27aaba3
to
df19ed0
Compare
can we merge this now? At least I am happy with how error messages are shown |
df19ed0
to
a1520b6
Compare
we don't have "admin cookbook" section in README. Should we create one? |
Olev Kartau <[email protected]> writes:
> How easily can the error be discovered in the log? This probably needs to go into an "admin cookbook" section in the README.md.
we don't have "admin cookbook" section in README. Should we create one?
Yes.
|
I change the style towards "less PRs" so that I dont create separate PR for small changes. Thus moving this change into new #133 , closing this PR |
This simple change fixes error hiding issue described in #115.
But note that it also changes semantics on failure:
now we return after 1st attempt failure, but original code would try creation in other remaining regions.
If we want to keep original semantics, we have to choose which error to report/return,
in case we try multiple times and there are multiple errors.
Perhaps should add log stmt showing error, in addition to returning error?