Skip to content

fix(resources): return 400 when path or source is missing - #2856

Merged
gtsteffaniak merged 1 commit into
gtsteffaniak:dev/v2.0.3from
justadityaraj:fix/resource-missing-path-status
Aug 28, 2026
Merged

gtsteffaniak merged 1 commit into
gtsteffaniak:dev/v2.0.3from
justadityaraj:fix/resource-missing-path-status

Conversation

@justadityaraj

@justadityaraj justadityaraj commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2801 — GET /api/resources returns 500 when path is empty or omitted.

Problem

An empty or omitted resource path reached the shared permission guard, which returned a plain error. ErrToStatus could not classify it and fell back to HTTP 500. A missing source followed the same path.

Fix

Wrap both missing-parameter errors with the existing ErrInvalidRequestParams sentinel. Every resource caller still uses the same guard, while ErrToStatus now maps these malformed requests to HTTP 400.

Deliberately not done

The issue's separate observations about users, cached permissions, and event logging are unrelated and remain unchanged.

User impact

API clients now receive a client-error status for malformed resource requests instead of mistaking them for server failures.

Verification

  • go test ./internal/web -run '^TestCheckPermissionsMissingParamsStatus$' -count=1 — passed.

  • GitHub Actions — all 22 repository checks passed, including backend/frontend tests and Playwright across the configured authentication modes.

  • git diff --check — passed.

  • A clear description of why it was opened.

  • A short title that best describes the change.

  • Must pass unit and integration tests, which can be run checked locally prior to opening a PR.

  • Any additional details for functionality not covered by tests.

checkPermissions rejected an empty path or source with a bare
fmt.Errorf, which ErrToStatus has no case for, so the default arm
turned a malformed request into a 500. GET /api/resources?source=x&path=
and the same call with no path at all both surfaced as a server error,
leaving clients unable to tell a bad request from a real failure.

Wrap both guards in ErrInvalidRequestParams, which ErrToStatus already
maps to 400. One shared guard covers every caller: the resource
handlers, the directory listing path, and WebDAV.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dbd0fbdf-dd84-4c5b-b169-81c89bf09142

📥 Commits

Reviewing files that changed from the base of the PR and between 609e1d6 and 477e7ff.

📒 Files selected for processing (2)
  • backend/internal/adapters/fs/files/files.go
  • backend/internal/web/resource_params_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Missing path and source errors from files.CheckPermissions now wrap errors.ErrInvalidRequestParams. Tests verify that these errors map to HTTP 400 responses.

Changes

Invalid parameter handling

Layer / File(s) Summary
Permission validation and status mapping
backend/internal/adapters/fs/files/files.go, backend/internal/web/resource_params_test.go
Missing path and source errors now wrap errors.ErrInvalidRequestParams. A table-driven test verifies that both cases map to http.StatusBadRequest.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 477e7

Malformed resource requests now return 400 instead of 500 without changing authorization or adding runtime dependencies. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: gtsteffaniak

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #2801 by wrapping missing-parameter errors with ErrInvalidRequestParams, which maps the response to HTTP 400 instead of HTTP 500. Tests cover missing path and source paramete…
Out of Scope Changes check ✅ Passed The code and test changes are limited to shared missing-parameter validation and its HTTP status behavior. No unrelated changes are present.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: return HTTP 400 when the resource path or source is missing.
Full details: Linked Issues check

Explanation

The changes address issue #2801 by wrapping missing-parameter errors with ErrInvalidRequestParams, which maps the response to HTTP 400 instead of HTTP 500. Tests cover missing path and source parameters.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gtsteffaniak

Copy link
Copy Markdown
Owner

im not seeing any actual changes here... just adjusting the error text?

@justadityaraj

justadityaraj commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

im not seeing any actual changes here... just adjusting the error text?

No no the actual change is the %w wrap.

both guards were returning a bare fmt.Errorf, so errors.Is matched nothing in ErrToStatus and it fell through to default -> 500. wrapping ErrInvalidRequestParams makes it hit this instead:

case errors.Is(err, libErrors.ErrInvalidRequestParams):
    return http.StatusBadRequest

so GET /api/resources with no path goes 500 -> 400. body was already fine ("path not provided"), it was just the status that was wrong which is what #2801 was about.

@gtsteffaniak

Copy link
Copy Markdown
Owner

ok that makes sense, I see that from the description now, I was just looking at the code and confused. This makes sense.

While this is a behavior change for the API, I think its a useful bugfix that belongs in v2.0.3-beta so I will target that.

@gtsteffaniak
gtsteffaniak changed the base branch from main to dev/v2.0.3 August 28, 2026 21:15
@gtsteffaniak
gtsteffaniak merged commit b799124 into gtsteffaniak:dev/v2.0.3 Aug 28, 2026
23 checks passed
@justadityaraj

Copy link
Copy Markdown
Contributor Author

ok that makes sense, I see that from the description now, I was just looking at the code and confused. This makes sense.

While this is a behavior change for the API, I think its a useful bugfix that belongs in v2.0.3-beta so I will target that.

Anytime, happy weekend :)

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.

GET /api/resources returns 500 when path is empty or omitted

2 participants