matryer/xbar · error
unable to open URL %s
Error message
unable to open URL %s
What it means
This error wraps the failure of the OS-level 'open' command launched by CommandService.OpenURL when the user clicks a menu-item href. It means the platform could not launch the default browser/handler for the given URL — e.g. the 'open' command exited non-zero or could not be started — not that the URL itself is invalid.
Source
Thrown at app/command_service.go:60
// WindowMinimise minimises the window.
func (c *CommandService) WindowMinimise() {
c.runtime.Window.Minimise()
}
// OpenPath opens a window.
func (c CommandService) OpenPath(path string) error {
err := c.runCommand("open", path)
if err != nil {
return errors.Wrapf(err, "unable to open path %q", path)
}
return nil
}
// OpenURL opens a window.
func (c CommandService) OpenURL(url string) error {
err := c.runCommand("open", url)
if err != nil {
return errors.Wrapf(err, "unable to open URL %s", url)
}
return nil
}
// OpenFile opens a file for editing.
func (c CommandService) OpenFile(path string) error {
err := c.runCommand("open", filepath.Join(pluginDirectory, path))
if err != nil {
return errors.Wrapf(err, "failed to open %q", path)
}
return nil
}
// runCommand runs the command, wiring up stdout and stderr, and
// inheriting the environment.
func (CommandService) runCommand(name string, args ...string) error {
cmd := exec.Command(name, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{View on GitHub (pinned to d624239058)
Solutions
- Validate the URL is absolute and well-formed (url.Parse + scheme check) before calling OpenURL
- Check a default browser is configured on the system
- Ensure the platform supports the `open` command
Example fix
// before
svc.OpenURL("xbar://open-plugin?id=abc def")
// after
u := url.URL{Scheme: "xbar", Opaque: "open-plugin", RawQuery: "id=abc"}
svc.OpenURL(u.String()) Defensive patterns
Strategy: validation
Validate before calling
// before OpenURL: require an absolute, parseable URL
u, err := url.Parse(rawURL)
if err != nil || u.Scheme == "" {
return fmt.Errorf("invalid URL %q", rawURL)
} Try / catch
// Go
if err := svc.OpenURL(rawURL); err != nil {
if strings.Contains(err.Error(), "unable to open URL") {
return fmt.Errorf("could not open %q in browser: %w", rawURL, err)
}
return err
} Prevention
- Build URLs with net/url instead of string concatenation
- Percent-encode query values with url.Values.Encode
- Ensure a default browser is configured
When it happens
Trigger: Calling CommandService.OpenURL with an invalid or unopenable URL, or when the underlying `open` command fails to execute (e.g. no default browser, non-macOS platform).
Common situations: Malformed URL strings (missing scheme, spaces); opening a URL that the OS cannot handle; running where `open` is not available.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- unable to open path %q
- failed to open %q
- not an xbar:// url
- unsupported action %q
- run in terminal script failed: %s
AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02).
Data as JSON: /api/errors/a62175350264b654.
Report an issue: GitHub.