kcl-lang / kpm

KCL Package Manager
https://kcl-lang.io
Apache License 2.0
27 stars 44 forks source link

kpm needs `Debug Mode` to show and record more detailed logs #366

Open zong-zhe opened 4 months ago

zong-zhe commented 4 months ago

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:

vinayakjaas commented 3 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.

zong-zhe commented 3 months ago

Hi @vinayakjaas 😄,

Welcome!

I have assigned this task to you, there are some more details.

This task mainly includes three parts,

  1. kpm's current error management is a bit confusing, you may need to investigate some go programming error management common patterns, and then design a simple and lightweight error throwing mechanism for kpm, and then.
  2. The second step is to add a log module to kpm, reuse some common log tripartite libraries in go language, and record this log during the program running.
  3. Finally, add switches to set the debug mode of the logging system, log redirection, and so on.

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.

vinayakjaas commented 3 months ago

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.

Benefits

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/

zong-zhe commented 3 months ago

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.

vinayakjaas commented 3 months ago

Hey @zong-zhe I open Pull Request which cover Error Handling part in proper way. The following changes have been made:

Updated errors.go

reporter.go

kpm.go



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