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

Allow caller to deal with failure #15

Open
TyeMcQueen opened this issue Jun 26, 2019 · 1 comment
Open

Allow caller to deal with failure #15

TyeMcQueen opened this issue Jun 26, 2019 · 1 comment

Comments

@TyeMcQueen
Copy link

Please update the "unsupported" case to be more useful. You could provide a browser.IsSupported() that returns true only on supported platforms.

I find the use of build-time handling of different platforms to be overly complex. After reviewing this module and considering writing a pull request, I just went with:

func openBrowser(url string) {
	cmd := "xdg-open"
	args := []string{url}

	switch runtime.GOOS {
	case "darwin":
		cmd = "open"
	case "windows":
		cmd = "rundll32"
		args = []string{"url.dll,FileProtocolHandler", url}
	}
	err := exec.Command(cmd, args...).Start()
	if err == nil {
		return
	}
	fmt.Printf("Failed to launch %s: %v", cmd, err)
	fmt.Printf("Load this URL in your browser:\n    %s\n", url)
}

because it could work on more types of Unix systems and more gracefully fails when assumptions are not met.

Adding support for the BROWSER environment variable to that would be even better.

@luna-duclos
Copy link
Collaborator

My suggestion would be that we define a static err ErrUnsupported and let you check on that, would that fix your problem ?

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

No branches or pull requests

2 participants