hashicorp/terraform · error

Error reading error message: %s

Error message

Error reading error message: %s

What it means

Raised in checkSCPStatus when the SCP protocol returns a non-zero status byte (indicating a remote error) and the subsequent attempt to read the human-readable error message line from the SCP response stream fails. The communicator already detected an SCP-level error but could not extract the textual detail, so only the transport-level read error is surfaced.

Source

Thrown at internal/communicator/ssh/communicator.go:638

	}

	return nil
}

// checkSCPStatus checks that a prior command sent to SCP completed
// successfully. If it did not complete successfully, an error will
// be returned.
func checkSCPStatus(r *bufio.Reader) error {
	code, err := r.ReadByte()
	if err != nil {
		return err
	}

	if code != 0 {
		// Treat any non-zero (really 1 and 2) as fatal errors
		message, _, err := r.ReadLine()
		if err != nil {
			return fmt.Errorf("Error reading error message: %s", err)
		}

		return errors.New(string(message))
	}

	return nil
}

var testUploadSizeHook func(size int64)

func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, size int64) error {
	if testUploadSizeHook != nil {
		testUploadSizeHook(size)
	}

	if size == 0 {
		// Create a temporary file where we can copy the contents of the src
		// so that we can determine the length, since SCP is length-prefixed.

View on GitHub (pinned to c9def3e214)

Solutions

  1. Inspect the underlying transport error wrapped by %s; if it indicates a broken pipe or EOF, the remote scp process died mid-transfer.
  2. Check remote disk space and scp availability (scp must be installed and on PATH).
  3. Retry the upload; transient network failures during large file transfers are common.
  4. Increase the connection timeout and verify network stability to the remote host.
Defensive patterns

Strategy: try-catch

Try / catch

// Check for SCP error message read failures and surface transport detail
if err := comm.Upload(dst, reader); err != nil {
    if strings.Contains(err.Error(), "Error reading error message") {
        // The remote scp process likely died mid-transfer
        log.Printf("[ERROR] SCP transfer failed with transport error: %v", err)
        return fmt.Errorf("scp transfer interrupted (remote scp may have crashed): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: During an SCP file or directory upload, the remote scp process sends a non-zero status code. The communicator calls r.ReadLine() to read the associated message, but the bufio reader hits an I/O error (connection reset, EOF, or timeout) before a newline is received.

Common situations: The remote scp process crashed or the SSH connection was severed mid-transfer (TCP reset, server kill, disk full on remote). The remote scp binary terminated abnormally before completing the error response.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/ea4bde6c1db4e012. Report an issue: GitHub.