-
Notifications
You must be signed in to change notification settings - Fork 63
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: add error tracing #479
Conversation
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.
Hi @zyllee, thanks for this contribution!
The issue you've addressed is out-of-date in terms of its implementation but not its requirements. We have since added internal/errs
to KraftKit which now stores error types (instead of iota
/int
s, they're string
s).
As discussed on Discord, the need for a error tracing system is still required and juju's errors module still seems like a good fit.
Based on the juju errors' README, you would technically need to use the juju errors
package to replace the internal package's definition of errors
with juju's, i.e.:
index 8206a12..4d88304 100644
--- a/internal/errs/defs.go
+++ b/internal/errs/defs.go
@@ -4,7 +4,9 @@
// You may not use this file expect in compliance with the License.
package errs
-import "errors"
+import
+ "github.com/juju/errors"
+)
However, we actually do NOT need to replace the above, in fact, since internal/errs
declares the same (subset) of errors
, this can be removed since they will be duplicate. Only when we add new error types (which is possible), would we need to restore this package with custom definitions. Let's hold off for now and simply remove this package.
Instead, to continue this work, I would recommend going through the KraftKit source code and replacing all instances of return fmt.Errorf
and errors.New
with valid juju errors
wrappers. This will allow us to a). classify each error into a category and b). allow us to unwrap each error nicely since the system will homogenise. The moment where errors are actually printed to the console occurs in cmdfactory.Main
:
kraftkit/cmdfactory/builder.go
Lines 175 to 184 in 06bef51
// Main executes the given command | |
func Main(ctx context.Context, cmd *cobra.Command) { | |
// Expand flag all dynamically registered flag overrides. | |
expandRegisteredFlags(cmd) | |
if err := cmd.ExecuteContext(ctx); err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
} |
Replace fmt.Printf(err)
with errors.ErrorStack(err)
For the first iteration on your side, this needs to be replace with juju errors' Unwrap
or Trace
method which will output the call stack or the list of errors which have occurred.
Finally, the code related to "user" look up can be removed entirely since this is out-of-scope of the project.
The screenshots above(except the first one) are running in cmd |
40ea1c2
to
ec96227
Compare
2f33ef3
to
c800c5b
Compare
39b3228
to
e2ea8f9
Compare
acad274
to
c17ee8d
Compare
Signed-off-by: Zeyu Li <mr.lizeyu@outlook.com>
c17ee8d
to
ed2fc34
Compare
Closing due to age and it requiring a large rebase. |
Prerequisite checklist
make fmt
on your commit series before opening this PR;Description of changes
To add the feature related to #34.
The juju package for error handling is currently imported. Wrote the test code.