Skip to content

fix(api): improve feedback record validation errors#67

Merged
xernobyl merged 5 commits into
mainfrom
chore/address_qa_findings
Apr 30, 2026
Merged

fix(api): improve feedback record validation errors#67
xernobyl merged 5 commits into
mainfrom
chore/address_qa_findings

Conversation

@xernobyl
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes ENG-791 and ENG-797.

This PR improves feedback record validation errors and local development startup:

  • Returns detailed RFC 7807 problem responses for invalid field_type values in POST /v1/feedback-records
  • Includes the failing field location, rejected value, and valid enum options
  • Replaces about:blank problem types with stable Hub problem type URIs
  • Updates OpenAPI examples to match runtime behavior
  • Updates make run so local development runs River migrations and starts both hub-api and hub-worker
  • Adds make run-api for API-only local runs
  • Updates README local setup instructions

Example invalid field_type response:

{
  "type": "https://hub.formbricks.com/problems/validation-error",
  "title": "Validation Error",
  "status": 400,
  "detail": "field_type has invalid value \"textt\"; must be one of: text, categorical, nps, csat, ces, rating, number, boolean, date",
  "errors": [
    {
      "location": "field_type",
      "message": "field_type has invalid value \"textt\"; must be one of: text, categorical, nps, csat, ces, rating, number, boolean, date",
      "value": "textt"
    }
  ]
}

How should this be tested?

  • make lint
  • go test ./internal/... ./pkg/...
  • make -n run
  • Local smoke test against running API/worker:
    • GET /health returned 200
    • Invalid POST /v1/feedback-records with field_type: "textt" returned 400 with detailed validation-error
    • Valid POST /v1/feedback-records with field_type: "text" returned 201

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Repository Guidelines
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran make build
  • Ran make tests (integration tests in tests/)
  • Ran make fmt and make lint; no new warnings
  • Removed debug prints / temporary logging
  • Merged the latest changes from main onto my branch with git pull origin main
  • If database schema changed: added migration in migrations/ with goose annotations and ran make migrate-validate

Appreciated

  • If API changed: added or updated OpenAPI spec and ran contract tests (make tests or API contract workflow)
  • If API behavior changed: added request/response examples or Swagger UI screenshots to this PR
  • Updated docs in docs/ if changes were necessary
  • Ran make tests-coverage for meaningful logic changes

@xernobyl xernobyl enabled auto-merge April 29, 2026 09:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

✱ Stainless preview builds

This PR will update the hub SDKs with the following commit message.

fix(api): improve feedback record validation errors
hub-openapi studio · code

Your SDK built successfully.
generate ✅

⚠️ hub-typescript studio · code

There was a regression in your SDK.
generate ✅build ❗lint ❗test ✅


This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
If you push custom code to the preview branch, re-run this workflow to update the comment.
Last updated: 2026-04-30 11:52:10 UTC

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

Walkthrough

This pull request makes changes across build configuration, documentation, and API error handling. The Makefile adds a new run-api target and modifies the run target to execute both worker and API processes with coordinated cleanup. The README documentation is updated to reflect this new workflow. The API's error response handling is refactored to comply with RFC 7807 problem details standards, with new response functions and constants for different HTTP status codes. Field-type validation is improved to provide structured error details, including location and invalid value information. The feedback records handler and related validation are updated to use the new error response patterns. The OpenAPI specification is updated with corrected problem type URIs and new validation error examples.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving feedback record validation error responses with better detail and formatting.
Description check ✅ Passed The PR description fully addresses the template requirements with clear sections, issue references, comprehensive testing instructions, and detailed checklist completion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
openapi.yaml (1)

204-215: ⚠️ Potential issue | 🟡 Minor

Update the validation examples to match runtime payloads.

The validation_error samples still use body.* locations and generic detail text, but internal/api/validation/validation.go now emits JSON-tag field names and formatted validation messages. Please refresh these examples so the docs match the API.

Suggested doc fix
- location: "body.field_id"
+ location: "field_id"
- location: "body.value_text"
+ location: "value_text"

Also applies to: 618-629

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openapi.yaml` around lines 204 - 215, The OpenAPI validation_error example
uses legacy "body.*" locations and generic detail; update the example under the
validation_error schema to match the runtime output produced by
internal/api/validation/validation.go by using the JSON-tag field names (e.g.,
"field_id" not "body.field_id"), formatting the detail to a runtime-style
summary, and making each errors[] entry use the same structure the validator
emits (location: "field_id", message: formatted validation message as produced
by the validator, and value: null); update the duplicate block referenced
similarly at the other occurrence so both examples mirror the actual JSON
emitted by the validation package.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Makefile`:
- Around line 113-133: The Makefile run target currently backgrounds go run
./cmd/worker which hides worker crashes and triggers checkmake's maxbodylength;
replace this by extracting the orchestration into a small wrapper script that
supervises the worker process (restarting it on unexpected exit and forwarding
INT/TERM/EXIT signals), then runs go run ./cmd/api in the foreground; update the
run target to call river-migrate and then invoke that wrapper (instead of
backgrounding go run ./cmd/worker and duplicating long trap logic), referencing
the existing run target, go run ./cmd/worker and go run ./cmd/api so the wrapper
performs supervision and graceful shutdown while keeping the Makefile short.

---

Outside diff comments:
In `@openapi.yaml`:
- Around line 204-215: The OpenAPI validation_error example uses legacy "body.*"
locations and generic detail; update the example under the validation_error
schema to match the runtime output produced by
internal/api/validation/validation.go by using the JSON-tag field names (e.g.,
"field_id" not "body.field_id"), formatting the detail to a runtime-style
summary, and making each errors[] entry use the same structure the validator
emits (location: "field_id", message: formatted validation message as produced
by the validator, and value: null); update the duplicate block referenced
similarly at the other occurrence so both examples mirror the actual JSON
emitted by the validation package.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1107dea8-012c-43e0-8487-d24b9d048f6e

📥 Commits

Reviewing files that changed from the base of the PR and between b22da19 and d1c2a94.

📒 Files selected for processing (9)
  • Makefile
  • README.md
  • internal/api/handlers/feedback_records_handler.go
  • internal/api/handlers/feedback_records_handler_test.go
  • internal/api/response/response.go
  • internal/api/response/response_test.go
  • internal/api/validation/validation.go
  • internal/models/feedback_records.go
  • openapi.yaml

Comment thread Makefile Outdated
Copy link
Copy Markdown
Contributor

@BhagyaAmarasinghe BhagyaAmarasinghe left a comment

Choose a reason for hiding this comment

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

looks good, only 1 small change

Comment thread internal/api/response/response.go
@xernobyl xernobyl added this pull request to the merge queue Apr 30, 2026
Merged via the queue into main with commit 2fe37d9 Apr 30, 2026
11 checks passed
@xernobyl xernobyl deleted the chore/address_qa_findings branch April 30, 2026 11:50
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.

2 participants