Open zong-zhe opened 4 months ago
Hey @zong-zhe, could you please assign this issue to me? I would like to work on it and come up with a solution.
Hi @vinayakjaas 😄,
Welcome!
I have assigned this task to you, there are some more details.
This task mainly includes three parts,
You can begin with a paperwork for Part 1, just update it into this issue, we can discuss and finally decide how to implement part one.
Hey @zong-zhe I go through by various blogs and documentation to find out common patterns for error management in go programming and I come to following conclusion
By going through all reading part I plan approach to solve issue (part 1).This approach will enhance the clarity, consistency, and maintainability of the error management system in kpm.
I am happy to listen you feedback and suggestions. So I move further accordingly Thank You
Reference :- https://earthly.dev/blog/golang-errors/ https://blog.logrocket.com/error-handling-golang-best-practices/
Hi @vinayakjaas 😄,
Good job!I think the overall is in the right direction, next, you may need to provide some pseudo-codes, some simple examples, or demo your idea in a PR to show more details.
For the three points, show a simple demo for them in a go file and same examples about how to use. A simple demo to help us understand better.
- We will introduce a custom error type, KpmError, which will encapsulate error messages and underlying errors. This custom error type will provide a clear and consistent way to handle various error scenarios within kpm.
- Utility functions will be created to wrap errors with additional context and ensure they conform to the KpmError type. These functions will be used throughout the application to generate and manage errors consistently.
- A centralized error handling mechanism will be implemented to log errors and provide meaningful messages to the users. This will involve creating a function that logs errors and prints user-friendly messages.
And one more thing I want to add about the logging system is that there may be some more non-error details in the logging system, which are not errors, but simply identifying what kpm is currently doing.
Hey @zong-zhe I open Pull Request which cover Error Handling part in proper way. The following changes have been made:
Simulate an Error in client.NewKpmClient(): Modify the client.NewKpmClient function temporarily to return an error. This will simulate a failure in client initialization.
func NewKpmClient() (*KpmClient, error) {
return nil, goerr.New("simulated client creation error")
}
Here I share two screenshots :-
![pr1](https://github.com/user-attachments/assets/fc4faf51-1d96-40cf-a58f-32ff206dc541)
Before changes in codebase
![PR2](https://github.com/user-attachments/assets/bc0aaa4f-4fc9-4623-8881-425036507fe3)
After changes in codebase
I not able to test for some other error so I request please review my PR
Feature Request
Is your feature request related to a problem? Please describe:
In some cases, the user needs to be able to see some more detailed log content to help the user understand what happened.
Describe the feature you'd like:
Add environment variables and CLI flag to control the
Debug Mode
on or off, and save the logs generated during kpm daily work in the log file in the ~/.kcl/kpm directory.Describe alternatives you've considered:
Teachability, Documentation, Adoption, Migration Strategy: