{"record":{"id":"69954e51c43da0a4","repo":"prestodb/presto","slug":"failed-to-redirect","errorCode":null,"errorMessage":"Failed to redirect","messagePattern":"Failed to redirect","errorType":"exception","errorClass":"RedirectException","httpStatus":null,"severity":"error","filePath":"presto-client/src/main/java/com/facebook/presto/client/auth/external/DesktopBrowserRedirectHandler.java","lineNumber":38,"sourceCode":"import static java.awt.Desktop.getDesktop;\nimport static java.awt.Desktop.isDesktopSupported;\n\npublic final class DesktopBrowserRedirectHandler\n        implements RedirectHandler\n{\n    @Override\n    public void redirectTo(URI uri)\n            throws RedirectException\n    {\n        if (!isDesktopSupported() || !getDesktop().isSupported(BROWSE)) {\n            throw new RedirectException(\"Desktop Browser is not available. Make sure your Java process is not in headless mode (-Djava.awt.headless=false)\");\n        }\n\n        try {\n            getDesktop().browse(uri);\n        }\n        catch (IOException e) {\n            throw new RedirectException(\"Failed to redirect\", e);\n        }\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":42,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-client/src/main/java/com/facebook/presto/client/auth/external/DesktopBrowserRedirectHandler.java#L20-L42","documentation":"After confirming a desktop browser is supported, DesktopBrowserRedirectHandler attempts Desktop.browse(uri) to complete external authentication. If browsing throws an IOException (browser launch failure, no associated browser application, OS-level error), the handler wraps it in this RedirectException.","triggerScenarios":"redirectTo(uri) succeeds the isSupported checks but Desktop.browse(uri) throws IOException — e.g. no default browser configured on the OS, xdg-open missing/broken on Linux, browser process fails to spawn, or an unsupported/badly formed URI is passed.","commonSituations":"Linux machines with no x-www-browser/xdg-open default; minimal desktop installs lacking a registered browser; corrupted default-browser associations; security software blocking AWT from spawning processes.","solutions":["Install and set a default browser on the machine (e.g. xdg-settings set default-web-browser firefox.desktop) and retry authentication.","Check the wrapped IOException (getCause()) for the underlying OS error and fix it (install xdg-open, repair browser registration).","Use a different RedirectHandler implementation that prints the auth URI for manual opening.","Avoid the browser flow by using non-external authentication credentials."],"exampleFix":"// before\nhandler.redirectTo(tokenUri); // fails on browser-less box\n// after\nif (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {\n    handler.redirectTo(tokenUri);\n} else {\n    System.out.println(\"Open manually: \" + tokenUri);\n}","handlingStrategy":"try-catch","validationCode":"java.awt.Desktop desktop = java.awt.Desktop.isDesktopSupported()\n        ? java.awt.Desktop.getDesktop() : null;\nif (desktop == null || !desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {\n    throw new IllegalStateException(\"No desktop browser; print URI manually instead\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    handler.redirectTo(uri);\n} catch (RedirectException e) {\n    e.getCause().printStackTrace(); // IOException: fix default browser / xdg-open\n    System.out.println(\"Open manually: \" + uri);\n}","preventionTips":["Ensure a default browser is registered (xdg-settings / OS defaults).","Install xdg-open on minimal Linux installs.","Catch RedirectException and fall back to printing the URL for manual opening.","Check e.getCause() (IOException) to diagnose the launch failure."],"tags":["authentication","ioexception","browser","redirect"],"backgroundTag":"browser-launch-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}