jesseduffield/lazygit · error

Failed to open URL %s Error: %v

Error message

Failed to open URL %s

Error: %v

What it means

Thrown when lazygit's hyperlink handler delegates a non-lazygit-edit URL to the OS via gui.os.OpenLink and the opener fails. OpenLink shells out to the platform-specific opener (xdg-open on Linux, 'open' on macOS, cmd start on Windows), so failure means the opener binary is missing, refuses the URL, or the URL is not openable by it.

Source

Thrown at pkg/gui/gui.go:420

	gui.g.SetOpenHyperlinkFunc(func(url string, viewname string) error {
		if strings.HasPrefix(url, "lazygit-edit:") {
			re := regexp.MustCompile(`^lazygit-edit://(.+?)(?::(\d*))?$`)
			matches := re.FindStringSubmatch(url)
			if matches == nil {
				return fmt.Errorf(gui.Tr.InvalidLazygitEditURL, url)
			}
			filepath := matches[1]
			if matches[2] != "" {
				lineNumber := utils.MustConvertToInt(matches[2])
				lineNumber = gui.helpers.Diff.AdjustLineNumber(filepath, lineNumber, viewname)
				return gui.helpers.Files.EditFileAtLine(filepath, lineNumber)
			}
			return gui.helpers.Files.EditFiles([]string{filepath})
		}

		if err := gui.os.OpenLink(url); err != nil {
			return fmt.Errorf(gui.Tr.FailedToOpenURL, url, err)
		}

		return nil
	})

	gui.g.SetUpdateQueueHighWaterMarkHandler(func(depth int) {
		gui.c.Log.Infof("User-event queue reached a new high-water mark: %d", depth)
	})

	gui.g.SetOnSelectSearchResultFunc(func(v *gocui.View, selectedLineIdx int) {
		ctx, ok := gui.helpers.View.ContextForView(v.Name())
		if ok {
			if searchableContext, ok := ctx.(types.ISearchableContext); ok {
				searchableContext.OnSearchSelect(selectedLineIdx)
			}
		}
	})

View on GitHub (pinned to c477a2959b)

Solutions

  1. On Linux ensure xdg-open exists (xdg-utils package) and a default browser is set via xdg-settings set default-web-browser
  2. Set the BROWSER or similar environment variable lazygit's opener honors, or configure the opener in lazygit settings (os.openLink / guessEditor-style config)
  3. On WSL install/dispatch wslview so opener invocations reach the Windows browser

Example fix

# before: no default browser
xdg-open https://example.com  # fails

# after
sudo apt install xdg-utils
xdg-settings set default-web-browser firefox.desktop
Defensive patterns

Strategy: retry

Validate before calling

# Linux: verify an opener exists before relying on link clicks
command -v xdg-open >/dev/null && xdg-settings get default-web-browser

Try / catch

Catch the error surfaced by the hyperlink handler, log the failing URL, and fall back to copying the URL to the clipboard or printing it for manual opening rather than failing silently.

Prevention

When it happens

Trigger: Clicking any http/https (or other non-lazygit-edit) link in a lazygit view while xdg-open is absent or no default browser is configured on Linux; OpenLink receiving a URL with a scheme no handler is registered for.

Common situations: Minimal Linux setups (sway/i3/headless/WSL without wslview) with no xdg-open or no default browser; SSH sessions without URL forwarding; a URL scheme (e.g. 'mailto:') with no registered handler.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/55df122a80fc8b63. Report an issue: GitHub.