{"record":{"id":"6770039fb9a07645","repo":"Netflix/Hystrix","slug":"hystrixcollapser-failed-while-executing","errorCode":null,"errorMessage":"HystrixCollapser failed while executing.","messagePattern":"HystrixCollapser failed while executing\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java","lineNumber":441,"sourceCode":"     * @throws HystrixRuntimeException\n     *             if an error occurs and a fallback cannot be retrieved\n     */\n    public ResponseType execute() {\n        try {\n            return queue().get();\n        } catch (Throwable e) {\n            if (e instanceof HystrixRuntimeException) {\n                throw (HystrixRuntimeException) e;\n            }\n            // if we have an exception we know about we'll throw it directly without the threading wrapper exception\n            if (e.getCause() instanceof HystrixRuntimeException) {\n                throw (HystrixRuntimeException) e.getCause();\n            }\n            // we don't know what kind of exception this is so create a generic message and throw a new HystrixRuntimeException\n            String message = getClass().getSimpleName() + \" HystrixCollapser failed while executing.\";\n            logger.debug(message, e); // debug only since we're throwing the exception and someone higher will do something with it\n            //TODO should this be made a HystrixRuntimeException?\n            throw new RuntimeException(message, e);\n        }\n    }\n\n    /**\n     * Used for asynchronous execution.\n     * <p>\n     * This will queue up the command and return a Future to get the result once it completes.\n     * \n     * @return ResponseType\n     *         Result of {@link HystrixCommand}{@code <BatchReturnType>} execution after passing through {@link #mapResponseToRequests} to transform the {@code <BatchReturnType>} into\n     *         {@code <ResponseType>}\n     * @throws HystrixRuntimeException\n     *             within an <code>ExecutionException.getCause()</code> (thrown by {@link Future#get}) if an error occurs and a fallback cannot be retrieved\n     */\n    public Future<ResponseType> queue() {\n        return toObservable()\n                .toBlocking()\n                .toFuture();","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapser.java#L423-L459","documentation":"In HystrixCollapser, unknown Throwables escaping the collapsed-command execution path are wrapped in a generic RuntimeException '<CollapserClass> HystrixCollapser failed while executing.' Only HystrixRuntimeExceptions (direct or as a cause) are rethrown as-is; everything else gets this wrapper so the failure still surfaces to the caller.","triggerScenarios":"A batch HystrixCommand run() throwing a non-Hystrix exception (NPE, IOException, etc.) during queue()/execute() of the collapser; errors inside mapResponseToRequests or the collapser's Scope plumbing bubbling up as raw Throwables.","commonSituations":"The underlying batch command's run() throws an unexpected runtime exception; a custom collapser's mapResponseToRequests has a bug; thread-uncaught errors (Errors, not Exceptions) escaping RxJava in older Hystrix 1.4/1.5 lines.","solutions":["Inspect getCause() of this RuntimeException — it holds the real failure from the batch command","Fix/handle the root exception inside the batch command run() or mapResponseToRequests","Let the batch command translate failures into HystrixRuntimeException (fallbacks / command semantics) so they propagate unwrapped","Add tests that exercise the collapser failure path to catch mapResponseToRequests bugs"],"exampleFix":"// before\ntry { collapser.queue().get(); } catch (ExecutionException e) { log.error(\"?\", e); }\n// after\ntry { collapser.queue().get(); }\ncatch (ExecutionException e) {\n  Throwable root = e.getCause() instanceof RuntimeException ? e.getCause().getCause() : e.getCause();\n  log.error(\"batch failed\", root); // root is the real error\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"catch (RuntimeException e) { if (e.getMessage().endsWith(\"HystrixCollapser failed while executing.\")) { Throwable root = e.getCause(); // handle real cause: retry, fallback, or translate } }","preventionTips":["Handle the cause chain, not the wrapper message","Make batch commands translate known failures into HystrixRuntimeExceptions so they propagate unwrapped","Test the collapser's failure path explicitly"],"tags":["java","hystrix","collapser","exception-wrapping"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}