{"record":{"id":"f0af88d6157e03da","repo":"SubtitleEdit/subtitleedit","slug":"the-forced-aligner-failed-exit-code-process-exit","errorCode":null,"errorMessage":"The forced aligner failed (exit code {process.ExitCode}).","messagePattern":"The forced aligner failed \\(exit code (.+?)\\)\\.","errorType":"exception","errorClass":"ForcedAlignerException","httpStatus":null,"severity":"error","filePath":"src/ui/Features/Files/ImportPlainText/CrispAsrAlignOnlyRunner.cs","lineNumber":99,"sourceCode":"        {\n            TryKill(process);\n            throw;\n        }\n\n        if (process.ExitCode != 0 || !File.Exists(outputFileName))\n        {\n            var detail = stdErr.ToString().Trim();\n            _log?.Invoke(detail);\n\n            // The aligner allocates its encoder activations up front, so a window that is\n            // too long for the available memory fails here rather than degrading.\n            if (detail.Contains(\"failed to allocate\", StringComparison.OrdinalIgnoreCase))\n            {\n                throw new ForcedAlignerException(\n                    \"The forced aligner ran out of memory on this window. Try a shorter window length.\", detail);\n            }\n\n            throw new ForcedAlignerException($\"The forced aligner failed (exit code {process.ExitCode}).\", detail);\n        }\n\n        return await File.ReadAllTextAsync(outputFileName, cancellationToken).ConfigureAwait(false);\n    }\n\n    private static void TryKill(Process process)\n    {\n        try\n        {\n            if (!process.HasExited)\n            {\n                process.Kill(true);\n            }\n        }\n        catch\n        {\n            // Killing a process that just exited on its own is not an error.\n        }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Features/Files/ImportPlainText/CrispAsrAlignOnlyRunner.cs#L81-L117","documentation":"The generic catch-all from CrispAsrAlignOnlyRunner.AlignAsync: the aligner exited non-zero (or wrote no .aligned.srt) and the stderr did not match the out-of-memory signature, so the runner wraps the exit code plus captured stderr into a ForcedAlignerException.","triggerScenarios":"process.ExitCode != 0 || !File.Exists(outputFileName), and the stderr detail does not contain 'failed to allocate'.","commonSituations":"Missing or wrong -am model path; corrupt/unreadable audio; text file length mismatch; unsupported sample rate; aligner binary crash; model/text encoding mismatch; cancelled mid-run leaving no output.","solutions":["Inspect the Detail property of the ForcedAlignerException — it carries the aligner's stderr verbatim, which states the real cause.","Confirm the -am model path exists and matches the aligner version.","Confirm the input WAV is 16 kHz mono PCM as the aligner expects.","Confirm the text file is non-empty and UTF-8.","Re-run with the aligner directly to reproduce, then fix the reported error."],"exampleFix":"// surface the detail\ncatch (ForcedAlignerException ex) {\n    logger.Error($\"aligner exit {ex.Detail}\");\n}","handlingStrategy":"try-catch","validationCode":"// Validate model + audio before invoking\nif (!File.Exists(_alignerModel)) throw new ArgException($\"Aligner model not found: {_alignerModel}\");\nif (!File.Exists(audioFileName)) throw new ArgException($\"Audio not found: {audioFileName}\");\nif (new FileInfo(audioFileName).Length == 0) throw new ArgException(\"Audio file is empty.\");","typeGuard":"null","tryCatchPattern":"try { return await runner.AlignAsync(a, t, ct); }\ncatch (ForcedAlignerException ex) { logger.Error($\"aligner failed: {ex.Message}\\ndetail: {ex.Detail}\"); throw; }","preventionTips":["Always log ex.Detail — it carries the aligner's own error text.","Pre-validate model path, audio existence, and sample rate.","Reproduce failing cases by invoking the aligner directly with the same args."],"tags":["subtitle-edit","forced-aligner","crispasr","process-exit-code","generic-error"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}