Repository navigation
fix(app): show webhook body template compile errors in the editor - #3350
Conversation
Compile the webhook body template as the user edits it (debounced) and show the Handlebars error, with its line and column, under the editor. A broken template, e.g. JSON-escaped quotes inside a helper call, previously gave no feedback until an alert failed to deliver.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: d15a797 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
[Medium impact] This PR appears safe to merge as an editor-feedback change. SummaryThe webhook editor now shows template compile errors after a 300 ms pause, including their line and column.
Reviews (3) · Last reviewed commit: "Merge branch 'main' into brandon/brandon..." · Reviewed by Greptile |
E2E Test Results✅ All tests passed • 416 passed • 1 skipped • 1160s
Tests ran across 4 shards in parallel. |
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
PR Review
3 finding(s): 🔴 0 critical · 🟠 2 major · 🔵 1 minor 2 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. The change is well-scoped and well-tested: 🟡 P2 — recommended
🔵 P3 nitpicks (3)
Reviewers (8): correctness, adversarial, kieran-typescript, testing, maintainability, julik-frontend-races, project-standards, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
jordan-simonovski
left a comment
There was a problem hiding this comment.
Could we possibly add validation to the API endpoint for this too?
I also think it may be worth having a /validate endpoint similar to our dashboards which allow us to validate configs like this during plan time in terraform.
Agreed - not in the PR description but I was planning to add backend validation for API/MCP/etc in the next PR :) |
|
@jordan-simonovski pt 2: #3365 |
…v2/webhooks/validate (#3365) Builds on #3350 (base is that branch; retarget to `main` once it merges). ## Why #3350 shows Handlebars compile errors in the webhook form, but saving still goes through, and the External API v2 and MCP never checked the body. A body that doesn't compile fails on every alert delivery. This rejects it at write time. It also adds the `/validate` endpoint requested on #3350 so Terraform can check webhook configs at plan time. ## What changed - Generic and incident.io body templates that don't compile now get a 400 on create, update and test, with the Handlebars message plus line/column, e.g. `Invalid webhook body template (line 1, column 29): Parse error on line 1: …`. Slack and empty bodies are skipped. - Internal API: `POST /webhooks`, `PUT /webhooks/:id`, `POST /webhooks/test` (rejects before sending). - External API v2 and MCP `clickstack_save_webhook` get the check through `createWebhook`/`updateWebhook`. MCP returns it as a user error. - New `POST /api/v2/webhooks/validate`, modelled on `POST /api/v2/dashboards/validate`. It parses with `externalWebhookCreateSchema`, runs the same URL and body checks as create, never saves, and always returns 200 with `{ valid, errors: [{ path, message }], normalized }`. It doesn't check name uniqueness. `openapi.json` is regenerated. - The check only compiles the template. It deliberately doesn't render it and parse the output as JSON. - The MCP `body` description and `docs/alert-webhook-template-variables.md` now say these templates are rejected. ## Tests `make dev-int FILE=webhooks`: 154 passed. Coverage: - 400 on create and update for the internal API, External API v2 and MCP - `/test` rejects without sending - `{{#if (eq state "ALERT")}}…` still saves - `/validate`: valid, invalid body, URL and body errors together, schema errors, 401 without a key
Summary
The webhook form now compiles the body template as you edit it and shows the Handlebars error under the editor, with its line and column. A template that doesn't compile used to save without any feedback, and the problem only surfaced when an alert failed to deliver (visible in server logs).
The common case is JSON-escaping quotes inside a Handlebars expression:
That's valid JSON but not a valid template. The form now shows
Template error on line 1, column 29with Handlebars' parse message. The intended template,{{#if (eq state "ALERT")}}, is invalid JSON as written but compiles, so it shows no error.{{ … }}is half-typed. Empty bodies are skipped, since they fall back to the service's default template. Slack bodies are skipped too; Slack never renders the body.getWebhookTemplateErrorin common-utils usesHandlebars.precompile. Delivery's extraeqhelper only matters at render time, so stock Handlebars reports the same compile errors delivery would hit.alert-webhook-template-variables.mdused the escaped-quote pattern itself and would not have compiled; it's fixed, and the page now explains how to quote strings inside{{ … }}.Screenshots or video
How to test on Vercel preview
Preview routes: /team
Steps:
data-testid="add-webhook-section-button"to open the webhook form.{"status": "{{#if (eq state \"ALERT\")}}firing{{/if}}"}and wait a moment.{"status": "{{#if (eq state "ALERT")}}firing{{/if}}"}and verify the error disappears.References