cloudflare/cloudflared · error

error waiting from command '%s': %w

Error message

error waiting from command '%s': %w

What it means

After piping a command's output, PipeCommandOutputToFile calls command.Wait(). This error wraps a non-zero exit or wait failure of the diagnostic command (e.g. journalctl), preserving the command string.

Source

Thrown at diagnostic/log_collector_utils.go:59

			"error copying stdout from %s to file %s: %w",
			command.String(),
			outputHandle.Name(),
			err,
		)
	}

	_, err = io.Copy(outputHandle, stderrReader)
	if err != nil {
		return nil, fmt.Errorf(
			"error copying stderr from %s to file %s: %w",
			command.String(),
			outputHandle.Name(),
			err,
		)
	}

	if err := command.Wait(); err != nil {
		return nil, fmt.Errorf(
			"error waiting from command '%s': %w",
			command.String(),
			err,
		)
	}

	return NewLogInformation(outputHandle.Name(), true, false), nil
}

func CopyFilesFromDirectory(path string) (string, error) {
	const defaultLogFilename = "cloudflared.log"

	// rolling logs have as suffix the current date thus
	// when iterating the path files they are already in
	// chronological order
	files, err := os.ReadDir(path)
	if err != nil {
		return "", fmt.Errorf("error reading directory %s: %w", path, err)

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Run the diagnostic with sufficient privileges (sudo/root) to read system logs
  2. Run the wrapped command manually to see its real error message inside the %w chain
  3. Adjust journalctl/log tool flags for the installed version

Example fix

// before
sudo cloudflared diagnostic collect
// after (verify underlying cmd first)
journalctl --no-pager -o json   # reproduce error directly, fix flags/privileges, then retry
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check privileges, e.g.
if _, err := exec.LookPath("journalctl"); err != nil { return err }

Try / catch

out, err := diagnostic.PipeCommandOutputToFile(ctx, fs, cmd, file)
if err != nil && strings.Contains(err.Error(), "error waiting from command") {
	log.Warn().Err(err).Str("cmd", cmd.String()).Msg("diagnostic command failed; skipping logs")
}

Prevention

When it happens

Trigger: command.Wait() returns error: the underlying command (journalctl, etc.) exited non-zero — bad flags, insufficient privileges to read journal, command crashed.

Common situations: Running 'cloudflared diagnostic' as non-root where journalctl needs privileges; journalctl flags changed across systemd versions.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/88a4b40270f7ccd7. Report an issue: GitHub.