Skip to content

[Code Quality] Servy.Service ProcessLauncher.cs — Duplicate FireAndForget check is dead code #707

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

File: src/Servy.Service/ProcessManagement/ProcessLauncher.cs, lines 64-94

The FireAndForget early return is duplicated. The first check at lines 65-68 returns before any buffer setup runs; the second identical check at lines 90-94 (with the same // 6. Handle execution mode comment) can never be true because options is not mutated between the two checks — it is unreachable dead code.

            // 6. Handle execution mode
            if (options.FireAndForget)
            {
                return process;
            }

            var stdoutBuffer = new StringBuilder();
            var stderrBuffer = new StringBuilder();

            if (psi.RedirectStandardOutput)
            {
                process.UnderlyingProcess.OutputDataReceived += (_, e) =>
                {
                    if (e.Data != null)
                        stdoutBuffer.AppendLine(e.Data);
                };
            }
            if (psi.RedirectStandardError)
            {
                process.UnderlyingProcess.ErrorDataReceived += (_, e) =>
                {
                    if (e.Data != null)
                        stderrBuffer.AppendLine(e.Data);
                };
            }

            // 6. Handle execution mode
            if (options.FireAndForget)
            {
                return process;
            }

            if (psi.RedirectStandardOutput) process.BeginOutputReadLine();
            if (psi.RedirectStandardError) process.BeginErrorReadLine();

Suggested fix

Delete lines 90-94 (the duplicate check and its comment). The early return at lines 65-68 is sufficient.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions