Comments (12)
can you implement the same for the parts as well?
Ok, I'll do the same and open PR. 😃
from grofer.
Sorry for posting in a short time. There's another solution. How do you think, @Gituser143 @MadhavJivrajani ?
- Defines a custom error in somewhere in
general
(for example,general/errors.go
), instead oferrCanceledByUser
incmd/root.go
. RenderCPUinfo()
returns the custom error whenq
orCtrl-C
pressed, and returnsctx.Err()
when receiving fromctx.Done()
.
from grofer.
The solution looks good! It'll ensure that returns are non-empty too! We could use this custom error in other functions used with grofer -c
and grofer proc
too.
If you'd implement this, it would be great! 😄
from grofer.
I concur with @Gituser143 this looks great, thanks!
from grofer.
Hi.
I read this proposal, and I've made some rough fixes.
master...egawata:wip_fix_error_handling
- Adds a channel to receive error from
info.GetCPULoad
. - Uses a context instead of channels, to communicate between goroutines. This would make a communication between goroutines a bit simpler.
- Pressing
q
works well to exit the program.
If this change helps fix this issue, I'll make a PR.
from grofer.
That's a better approach @egawata , thanks!
That does simplify error handling in this case. This got me searching for better ways to handle errors in a concurrent setting and I'd like your opinion on using errgroup which is basically meant for synchronizing, handling and passing errors occurred in one or more related goroutines. The idea remains the same as you suggested, using contexts
but this might simplify things further in our case.
Let me know what you think!
from grofer.
@MadhavJivrajani
Thank you for your kind advice! I've tried rewriting it with errgroup
.
master...egawata:wip_fix_error_handling_by_errgroup
I also think that is very simple and right solution to our case. 😄
from grofer.
It looks good for the most part, error handling seems to work great, I had a few queries which I was hoping you could address:
- Why is
errCanceledByUser
a new type of error? - Since you've use
errgroup
group, instead of returning errors in eacheg.Go(...)
would it be better to calleg.Wait()
since that will collectively wait for all of the associated goroutines to complete as well as collect errors from them and return it back to the caller?
from grofer.
Thank you for your advice 😃
Why is errCanceledByUser a new type of error?
All goroutines are canceled when one of eg.Go()
in errgroup returns non-nil error. To accomplish this, each eg.Go()
section should return error, even if there is actually no error.
Now overallGraph.RenderCPUinfo
in the second eg.Go()
returns no error (maybe when q
pressed), so I make it return dummy error (errCanceledByUser
) Of course, it shouldn't be handled as an error.
would it be better to call eg.Wait() since that will collectively wait for all of the associated goroutines to complete as well as collect errors from them and return it back to the caller?
In my code, it seems eg.Wait()
would be called, wait until all eg.Go()
to complete, and return the first error (if any) properly.
If you think it is better to return the error to its caller (meaning cobra
), only adding return err
will do that, although it makes error messages too verbose.
Please give me your opinion if I've misunderstood something. Thanks!
from grofer.
Oh alright, that makes sense, please go ahead and open the PR and we can move forward with this!
Currently, you've implemented error handling only for grofer -c
, can you implement the same for the parts as well? Starting with the else
clause in root.go
, error handling would need to be implemented for all aspects that have a TUI component which includes grofer proc [-p PID][-r refresh_rate]
.
For example, in serveStats.go
, errors are not being handled correctly.
Thanks!
from grofer.
@egawata when you receive from the channel of ctx.Done
wouldn't it make sense to return ctx.Err()
instead of a simple return? What I see from your changes to RenderCPUinfo()
function, you're waiting on the return values of this function back in root.
If there's something I'm missing please let me know. Thanks!
from grofer.
@Gituser143
Thank you for your opinion! 😃
I think it is a good style of func to return an error which indicates the reason, or nil if everything has gone well. I agree returning ctx.Err()
is better than a simple error.
The main reason why I don't do that is that the error will always be discarded. At the time the routine in RenderCPUinfo()
receives from ctx.Done
channel, other goroutine in the same errgroup has already returned a non-nil error. eg.Wait()
returns only the first non-nil error from other goroutine, not RenderCPUinfo()
.
Again, I think adding a return value of type error
to RenderCPUinfo()
is good, but we would be better wait to do it until we really need it. How do you think?
from grofer.
Related Issues (20)
- [FEATURE REQ] Add keybind to navigate to child process in grofer proc HOT 3
- [FEATURE REQ] Add Dockerfile for `grofer` HOT 4
- [BUG] Incorrect timestamps
- [FEATURE REQ] Add keybindings for sorting output for `grofer proc` HOT 2
- [FEATURE REQ] add key bindings for `kill`ing and `restart`ing docker containers from `grofer` HOT 4
- [BUG] grofer fails in tmux HOT 4
- [FEATURE REQ] Add version number to about page HOT 31
- [BUG] Incorrect unit in `RoundValues()` HOT 2
- [BUG] Selectoed process out of bounds in `grofer proc`
- [Enhancement] Improve the way container actions are handled
- [FEATURE REQ] A screen that can track battery usage HOT 6
- [FEATURE REQ] Kubernetes Monitoring and Dashboard HOT 8
- [FEATURE REQ] Add an action table for the overall container page
- [FEATURE REQ] provide support for different signal types HOT 5
- [BUG] incorrect pid validation in `proc` command HOT 6
- [FEATURE REQ] add monitoring of system resources given docker container id
- [Enhancement] add cleaner and more efficient error handling HOT 1
- -c flag throws error HOT 3
- [FEATURE REQ] add the `s`(pause) key-binding to help menus HOT 2
- [DOC] document using `grofer export` format HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grofer.