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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt(hgctl/dashboard): avoid printing error messages cannot open browser #665

Merged
merged 8 commits into from
Dec 6, 2023

Conversation

sjcsjc123
Copy link
Collaborator

Ⅰ. Describe what this PR did

Avoid printing error messages when commands do not exist.

Ⅱ. Does this pull request fix one issue?

fixes #652

Ⅲ. Why don't you add test cases (unit test/integration test)?

This is related to the presence or absence of a GUI.

Ⅳ. Describe how to verify it

This is executed in the centos container of Docker.

image

This is executed in local.

image

Ⅴ. Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2023

CLA assistant check
All committers have signed the CLA.

@CH3CHO
Copy link
Collaborator

CH3CHO commented Dec 5, 2023

Why are there only a plain URL showing in the terminal?

@sjcsjc123
Copy link
Collaborator Author

sjcsjc123 commented Dec 5, 2023

Is it okay to add and print this information?
image

@CH3CHO
Copy link
Collaborator

CH3CHO commented Dec 5, 2023

Is it okay to add and print this information? image

Could you post a screenshot of the final output? Thanks.

@sjcsjc123
Copy link
Collaborator Author

Of course.
image

func openCommand(command string, args ...string) error {
_, err := exec.LookPath(command)
if err != nil {
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we return err but a nil here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the command cannot be found, it will return err. At this time, simply print a reminder and return nil. If it returns err, there will be a step to print err later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if a function cannot perform the task it claims to perform, an error should be returned. And if there is no error returned, how should we determine whether to show the corresponding message then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

How about this? If the command cannot be found, it will prompt that the browser cannot be opened; Otherwise, return err.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

Choose a reason for hiding this comment

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

Which one is better?

  1. Display an error message in openCommand and return nil
  2. Return an error in openCommand function and show the corresponding error message in the caller

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tend to print it out in the opencommand method and then change it to a method with no return parameters.

@Xunzhuo
Copy link
Collaborator

Xunzhuo commented Dec 5, 2023

We already have a flag for it: --browser=false

@sjcsjc123
Copy link
Collaborator Author

We already have a flag for it: --browser=false

By default, browser is set to true, and users may not notice this flag. Running the default command without a GUI interface will also print the error. This is just my suggestion.

@Xunzhuo Xunzhuo changed the title bugfix: Avoid printing error messages when commands do not exist opt(hgctl/dashboard): avoid printing error messages cannot open browser Dec 6, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2023

Codecov Report

Merging #665 (dbd90d4) into main (1dbb130) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #665      +/-   ##
==========================================
- Coverage   35.63%   35.60%   -0.03%     
==========================================
  Files          73       73              
  Lines       10439    10447       +8     
==========================================
  Hits         3720     3720              
- Misses       6432     6440       +8     
  Partials      287      287              
Files Coverage Δ
pkg/cmd/hgctl/dashboard.go 0.00% <0.00%> (ø)

Copy link
Collaborator

@Xunzhuo Xunzhuo left a comment

Choose a reason for hiding this comment

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

Current approach looks good, this is an opt on error msg but not a bug fix.

@Xunzhuo Xunzhuo merged commit a554ee1 into alibaba:main Dec 6, 2023
7 checks passed
@sjcsjc123 sjcsjc123 deleted the bufix-openBrowser branch January 14, 2024 06: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.

hgctl dashboard command fails on Linux without xdg-open command installed
5 participants