{"record":{"id":"a62175350264b654","repo":"matryer/xbar","slug":"unable-to-open-url-s","errorCode":null,"errorMessage":"unable to open URL %s","messagePattern":"unable to open URL (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/command_service.go","lineNumber":60,"sourceCode":"// WindowMinimise minimises the window.\nfunc (c *CommandService) WindowMinimise() {\n\tc.runtime.Window.Minimise()\n}\n\n// OpenPath opens a window.\nfunc (c CommandService) OpenPath(path string) error {\n\terr := c.runCommand(\"open\", path)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"unable to open path %q\", path)\n\t}\n\treturn nil\n}\n\n// OpenURL opens a window.\nfunc (c CommandService) OpenURL(url string) error {\n\terr := c.runCommand(\"open\", url)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"unable to open URL %s\", url)\n\t}\n\treturn nil\n}\n\n// OpenFile opens a file for editing.\nfunc (c CommandService) OpenFile(path string) error {\n\terr := c.runCommand(\"open\", filepath.Join(pluginDirectory, path))\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to open %q\", path)\n\t}\n\treturn nil\n}\n\n// runCommand runs the command, wiring up stdout and stderr, and\n// inheriting the environment.\nfunc (CommandService) runCommand(name string, args ...string) error {\n\tcmd := exec.Command(name, args...)\n\tcmd.SysProcAttr = &syscall.SysProcAttr{","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/app/command_service.go#L42-L78","documentation":"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.","triggerScenarios":"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).","commonSituations":"Malformed URL strings (missing scheme, spaces); opening a URL that the OS cannot handle; running where `open` is not available.","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"],"exampleFix":"// before\nsvc.OpenURL(\"xbar://open-plugin?id=abc def\")\n// after\nu := url.URL{Scheme: \"xbar\", Opaque: \"open-plugin\", RawQuery: \"id=abc\"}\nsvc.OpenURL(u.String())","handlingStrategy":"validation","validationCode":"// before OpenURL: require an absolute, parseable URL\nu, err := url.Parse(rawURL)\nif err != nil || u.Scheme == \"\" {\n    return fmt.Errorf(\"invalid URL %q\", rawURL)\n}","typeGuard":null,"tryCatchPattern":"// Go\nif err := svc.OpenURL(rawURL); err != nil {\n    if strings.Contains(err.Error(), \"unable to open URL\") {\n        return fmt.Errorf(\"could not open %q in browser: %w\", rawURL, err)\n    }\n    return err\n}","preventionTips":["Build URLs with net/url instead of string concatenation","Percent-encode query values with url.Values.Encode","Ensure a default browser is configured"],"tags":["command-execution","url","macos"],"backgroundTag":"invalid-url","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}