Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: improve error messages, add color coding and debug logging #19781

Merged
merged 4 commits into from Nov 7, 2023

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Nov 6, 2023

This PR updates errors (e.g., also the error stated in yesterday's discord chat) and makes them uniform. It adds some color coding (similar to our regular V errors or cargo) and replaces verbose prints where they were solely used for debugging with debug logs that will be printed when run with the VPM_DEBUG env var.

  • Errors:
    Current
    Screenshot_20231106_091326

    New
    Screenshot_20231106_091830

  • Logs:

    Screenshot_20231106_084729

Ofc. colors differ from the screenshots based on terminal configuration.

Also, the work on VPM implements new errors or extends existing ones. Updating them allows working with the new errors already, instead of creating ones that match the old ones, only to update them later.

馃 Generated by Copilot at a8b9e99

This pull request improves the error handling, logging, and output formatting of the vpm tool, using the log and term modules and some new helper functions. It also fixes some bugs and validations in the module metadata and dependency resolution features. It updates the test files to match the new output and error messages.

馃 Generated by Copilot at a8b9e99

  • Add new error handling and logging functions vpm_error and vpm_log to common.v, and use them to replace eprintln, panic, and verbose_println in various places, respecting the verbosity settings and providing more details if needed (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Add a new struct ErrorOptions to common.v, and use it to pass optional details and verbosity settings to the vpm_error function, allowing more flexibility and control over how errors are displayed to the user (link)
  • Fix a bug in the get_module_meta_info function in common.v, where the cmd variable was interpolated twice, causing an invalid command to be executed (link)
  • Add a validation check for the module name in the get_module_meta_info function in common.v, where it returns an error if the name is less than two characters long or does not start with a digit or a letter (link)
  • Remove the redundant quotation marks around the module name and url in the get_module_meta_info and resolve_dependencies functions in common.v, where they are already interpolated with the ${} syntax (link,link)
  • Replace the eprintln function with the vpm_error function in the get_mod_date_info, get_all_modules, ensure_vmodules_dir_exist, increment_module_download_count, and resolve_dependencies functions in common.v, where they report various errors related to the retrieval, creation, and parsing of module data (link,link,link,link,link)
  • Replace the eprintln function with the vpm_error function in the valid_final_path_of_existing_module function in common.v, where it reports various errors if the module name or path is invalid or unsupported, and make the error messages more consistent and informative (link)
  • Replace the quotation marks with backticks around the module names and url in the test_install_from_vmod, test_install_from_git_url, test_install_from_incomplete_url functions in install_test.v, and the test_install_from_vmod and test_install_from_git_url functions in dependency_test.v, where they assert that the output of the v install command contains the expected messages, and make the test output more consistent with the actual output of the vpm tool (link,link,link,link,link)
  • Replace the exact string comparison with a substring check in the test_install_from_incomplete_url function in install_test.v, where it asserts that the output of the v install command contains the expected error message, and make the test more robust and flexible (link)
  • Remove the redundant quotation marks around the joined keywords in the vpm_search function in search.v, where they are already interpolated with the ${} syntax (link)
  • Remove the redundant quotation marks around the vlib module name in the vpm_search function in search.v, where they are already interpolated with the ${} syntax (link)
  • Replace the quotation marks with backticks around the module name in the vpm_search function in search.v, where it prints a suggestion on how to install the module, and make the output more consistent with the actual output of the vpm tool (link)
  • Add an import to the log module in settings.v, and use it for the new vpm_log function that uses the log module to output debug messages (link)
  • Add a check for the VPM_DEBUG environment variable in the get_settings function in settings.v, where it sets the log level to debug if the variable is not empty (link)
  • Change the condition for the no_dl_count_increment field in the get_settings function in settings.v, where it checks if the VPM_NO_INCREMENT environment variable is not empty instead of equal to 1 (link)
  • Add a call to the vpm_log function in the main function in vpm.v, where it logs the parameters passed to the vpm tool, and provide more debug information for the vpm tool (link)
  • Replace the eprintln function with the println function in the main function in vpm.v, where it prints the list of outdated or installed modules, and avoid printing the list as an error (link,link)
  • Replace the help.print_and_exit function with the vpm_error function and the help.print_and_exit function in the main function in vpm.v, where it reports an error and prints the help message if an unknown command is passed to the vpm tool, and make the code more consistent and concise (link)

Comment on lines +155 to +157
vpm_error(err.msg(),
verbose: true
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that formatted by vfmt?

Copy link
Member Author

@ttytm ttytm Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, vfmt doesn't behave when there is a call_expr before args that are part of a params struct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#19795 should fix it

cmd/tools/vpm/common.v Outdated Show resolved Hide resolved
cmd/tools/vpm/common.v Outdated Show resolved Hide resolved
cmd/tools/vpm/common.v Outdated Show resolved Hide resolved
cmd/tools/vpm/vpm.v Outdated Show resolved Hide resolved
cmd/tools/vpm/common.v Outdated Show resolved Hide resolved
cmd/tools/vpm/common.v Outdated Show resolved Hide resolved
cmd/tools/vpm/install.v Outdated Show resolved Hide resolved
Co-authored-by: JalonSolov <37967083+jalonsolov@users.noreply.github.com>
Co-authored-by: Delyan Angelov <26967+jalonsolov@users.noreply.github.com>
@spytheman spytheman merged commit 93d5c2d into vlang:master Nov 7, 2023
42 checks passed
@ttytm ttytm deleted the vpm/improve-stdout branch November 13, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants