Skip to content

Failing commands that use 2>&1 lose their error text #113

Closed

Description

@TMHSDigital

Summary

When a remote command exits non-zero, execSSH builds the error from stderr only. About 30 tool commands redirect 2>&1, so stderr is empty and the user gets Command exited with code N with the real error message thrown away.

Where

  • mcp-server/src/utils/ssh-api.ts:345-346 (execSSH)
  • mcp-server/src/utils/errors.ts:379 (CommandFailedError)
  • Affected commands include composeUp/Down/Pull/Ps, backupRestore.ts:40, backupDiff.ts:22, volumeBackup.ts:29, certRenew.ts:44, certCheck.ts:25, systemdServices.ts:26, ufwStatus.ts:12, fail2banStatus.ts:22

Details

} else if (code !== 0 && code !== null && code !== undefined) {
  reject(new CommandFailedError(command, code, stderr.toString()));

stdout, which holds the merged output for 2>&1 commands, is dropped. Two visible consequences:

  • systemctl status exits 3 for an inactive unit, so asking homelab_systemdServices for a stopped service returns only an exit code.
  • certCheck has a friendly fallback (certCheck.ts:30) that can never run, because openssl x509 exits non-zero when no certificate was received.

Impact

The failures users most need explained (invalid compose file, restore errors, certbot errors, stopped units) come back as a bare exit code plus the command line.

Steps to reproduce

  1. Call homelab_systemdServices with unit set to an inactive unit.
  2. Result: [CommandFailedError] Command exited with code 3.

Suggested fix

  • In execSSH, fall back to the tail of stdout when stderr is empty (bounded, for example the last 40 lines), or include both.
  • In systemdServices, treat exit code 3 from systemctl status as a successful read.
  • In certCheck, return the fallback message when the x509 step fails.

Acceptance criteria

  • A failing 2>&1 command returns its output in the error.
  • systemdServices shows status for inactive units.
  • Test in utils/__tests__/ssh-exec.test.ts for a non-zero exit with output only on stdout.

Getting started

  • Relevant files: mcp-server/src/utils/ssh-api.ts, mcp-server/src/utils/__tests__/ssh-exec.test.ts
  • How to run tests: cd mcp-server && npm install && npm test

Filed by repo-audit/full-audit at a59395f. Severity: medium. Effort: S. audit-key: bug|mcp-server/src/utils/ssh-api.ts|execSSH-stderr

Activity

  1. added
    bug
    good first issue
    severity: medium
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuemcp-serverseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions