Skip to content

fix(cmd,remotefs): classify ErrNotExist on the full stderr, not the m… - #441

Merged
kke merged 2 commits into
mainfrom
fix/429-isnotexist-truncated-stderr
Aug 20, 2026
Merged

kke merged 2 commits into
mainfrom
fix/429-isnotexist-truncated-stderr

Conversation

@kke

@kke kke commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

…essage

isNotExist matched "No such file or directory" in err.Error(), and the executor shortened a command's stderr to 100 characters before building that error. Coreutils print the path first and the reason last, so a long enough path pushed the reason out of the message and the classification silently flipped: the same missing file was fs.ErrNotExist at a short path and an opaque command failure at a long one. All six operations that classify through the helper -- Sha256, Chmod, Chown, ChownInt, ChownTree and ChownTreeInt -- depended on the path length.

The executor now builds a *cmd.ProcessError, which keeps the command's stderr in full and shortens it only when rendering its message, so log output is unchanged. cmd.StderrOf reaches the full text, and isNotExist reads that instead of the message, falling back to the message for errors that do not come from a command and carry no stderr of their own.

Remaining limitations, unchanged by this: absence is still inferred from a diagnostic rather than reported in a structured form, so it stays sensitive to command wording and to locale -- LC_ALL=C is set on the stat command but not on chmod, chown or sha256sum. And an exit status of 1 covers a missing path and a permission failure alike, so this does not separate ErrNotExist from ErrPermission. Both need the commands to report why they failed.

Fixes #429

…essage

isNotExist matched "No such file or directory" in err.Error(), and the
executor shortened a command's stderr to 100 characters before building that
error. Coreutils print the path first and the reason last, so a long enough
path pushed the reason out of the message and the classification silently
flipped: the same missing file was fs.ErrNotExist at a short path and an
opaque command failure at a long one. All six operations that classify
through the helper -- Sha256, Chmod, Chown, ChownInt, ChownTree and
ChownTreeInt -- depended on the path length.

The executor now builds a *cmd.ProcessError, which keeps the command's stderr
in full and shortens it only when rendering its message, so log output is
unchanged. cmd.StderrOf reaches the full text, and isNotExist reads that
instead of the message, falling back to the message for errors that do not
come from a command and carry no stderr of their own.

Remaining limitations, unchanged by this: absence is still inferred from a
diagnostic rather than reported in a structured form, so it stays sensitive
to command wording and to locale -- LC_ALL=C is set on the stat command but
not on chmod, chown or sha256sum. And an exit status of 1 covers a missing
path and a permission failure alike, so this does not separate ErrNotExist
from ErrPermission. Both need the commands to report why they failed.

Fixes #429

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke kke added the bug Something isn't working label Aug 20, 2026
@kke
kke requested a lite review from Copilot August 20, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes remotefs’s ErrNotExist classification so it no longer depends on path length by ensuring the full command stderr remains accessible for classification (while still keeping log/error messages readable via truncation only at render time).

Changes:

  • Add cmd.ProcessError that preserves full stderr on the error value and truncates only when formatting Error().
  • Update remotefs.isNotExist to classify based on full stderr via cmd.StderrOf(err), with a fallback to err.Error().
  • Add regression tests covering multiple path lengths and the sudo-decorated/chained runner path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
remotefs/posixfs.go Switch isNotExist to match against full command stderr (fallback to message).
remotefs/posixfs_test.go Add regression tests for path-length independence and sudo chaining.
cmd/processerror.go Introduce ProcessError + StderrOf to retain full stderr while truncating only in Error().
cmd/processerror_test.go Add tests validating message truncation vs full stderr retention and errors.As reachability.
cmd/executor.go Preserve full cleaned stderr and return *ProcessError instead of embedding truncated stderr into the wrapped error.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/processerror.go Resolved
%v is the conventional verb for an error value. The review note this
addresses claimed %s does not format errors and renders as %!s(...), which
is not the case -- fmt calls Error() for the error interface under %s too,
and the message assertions in cmd/processerror_test.go pass either way. The
change is idiomatic rather than a fix.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

cmd/executor.go:355

  • The doc comment says the “full output” stays available, but cleanStderr intentionally normalizes stderr (trims and collapses newlines, and strips CLIXML). It’s untruncated, but not the raw/full stderr; please adjust wording to avoid misleading callers.
// cleanStderr collapses a command's stderr into a single line and strips the
// CLIXML framing PowerShell wraps its error records in. It deliberately does not
// shorten the result: that happens in [ProcessError.Error], so the full output
// stays available to callers through [StderrOf].

cmd/processerror.go:47

  • ProcessError/StderrOf comments currently say “everything” / “in full”, but stderr is preprocessed (trimmed/newlines collapsed/CLIXML stripped) before being stored. It’s untruncated, but not the raw stderr; updating the comments will make the contract clearer.
// Stderr returns everything the command wrote to its standard error, without
// the shortening applied to the error message.
func (e *ProcessError) Stderr() string {
	return e.stderr
}

remotefs/posixfs.go:745

  • Grammar: “coreutils” is plural here; the comment should read “coreutils gives”.
// errNoSuchFile is the reason coreutils give for a path that is not there. They
// print the path first and the reason last, so the reason is exactly what is
// lost when a message is shortened.

@kke
kke merged commit cce3962 into main Aug 20, 2026
17 checks passed
@kke
kke deleted the fix/429-isnotexist-truncated-stderr branch August 20, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remotefs: isNotExist misclassifies by path length, because stderr is truncated to 100 characters

2 participants