Skip to content

fix(files): return errors from files rm instead of emitting them - #11491

Open
amalsaidov wants to merge 1 commit into
ipfs:masterfrom
amalsaidov:fix/files-rm-error-response
Open

amalsaidov wants to merge 1 commit into
ipfs:masterfrom
amalsaidov:fix/files-rm-error-response

Conversation

@amalsaidov

Copy link
Copy Markdown

This fixes a regression in how ipfs files rm reports failures.

Problem

When a path cannot be removed (for example removing an MFS path that does not exist), the command emitted each error as a regular stream output value and then returned a generic can't remove some files error. Over the RPC API this made /api/v0/files/rm respond with HTTP 200 and a plain, non-JSON string body, so clients that decode the error response got invalid JSON. This is a regression from v0.11 (the behavior in v0.10 was HTTP 500 with a JSON error body).

Fix

Return the errors (errors.Join) instead of emitting them. The RPC API now answers with HTTP 500 and a JSON error body:

HTTP/1.1 500 Internal Server Error
Content-Type: application/json

{"Message":"/foo/keks: file does not exist","Code":0,"Type":"error"}

When several paths fail, all failures are reported instead of a single generic message. On the CLI the real error is printed to stderr with a non-zero exit code, and the success path stays silent (like Unix rm).

Testing

Added test/cli coverage under TestFilesRm:

  • files rm of a missing path over the RPC API returns HTTP 500 with a valid JSON error body.
  • files rm of several missing paths reports each failing path.

Verified locally:

  • go build ./core/commands/...
  • go test ./core/commands/...
  • go test ./test/cli/... -run TestFilesRm -v (all subtests pass)
  • gofmt -l clean, go vet clean

AI-assisted; directed, reviewed and tested by the author.

References

files rm emitted each failure as a stream output value and then returned
a generic "can't remove some files" error. Over the RPC API this made
/api/v0/files/rm answer with HTTP 200 and a plain, non-JSON string body on
failure, a regression introduced in v0.11 that broke clients decoding the
error response.

Return the joined errors instead. The command now responds with HTTP 500
and a JSON error body, and reports every failing path rather than a generic
message. On the CLI this surfaces the real error on stderr with a non-zero
exit code.

Added a test/cli regression test covering the RPC JSON error response and
the multi-path failure output.

AI-assisted; directed, reviewed and tested by the author.
@amalsaidov
amalsaidov requested a review from a team as a code owner November 11, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in error responses from /api/v0/files/rm

1 participant