All jobs

Add Error Boundaries to a Vue App

Yes. An agent wraps your Vue 3 router view in an error boundary, adds a global errorHandler and a router.onError fallback, keeps Playwright green and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how errors surface today. In an app shaped like realworld-apps/vue-realworld-example-app, package.json has vue ^3.5.0, vue-router ^5.1.0, pinia ^3.0.0 and vite ^8.0.16, scripts for serve, build, lint with eslint-plugin-vue's flat/essential config, and test:e2e, which runs the RealWorld Playwright suite from the realworld git submodule against bun run serve on port 8080. src/main.js creates the app, installs pinia and the router, and registers a router.beforeEach that awaits auth.checkAuth() and sends guarded routes to /login; it sets no app.config.errorHandler. src/App.vue renders the header, <router-view> and the footer with nothing around them. src/router/index.js lazy-loads every view with a dynamic import and has no onError. src/common/api.service.js throws an Error carrying response: { status, data } for HTTP failures and no response for network ones; src/common/errors.js and components/ListErrors.vue turn data.errors into the list the login and register forms show. src/views/Article.vue swallows load failures in beforeRouteEnter with .catch(() => null) and renders whatever the store holds, so a failed fetch shows an empty article, and Home.vue and the stores keep no error state. A render error anywhere logs to the console and leaves the tree as it was, and a failed chunk import leaves the old view on screen.

The change is three small pieces that fit what is there. src/components/ErrorBoundary.vue uses onErrorCaptured to catch an error thrown by anything in its default slot during render, setup or a watcher, stores it, returns false so it does not also reach the global handler, and renders a fallback in the RealWorld markup (a container with the message and a Try again button that clears the state and renders the slot again) while the header and footer stay. App.vue wraps <router-view> in it, keyed by the route's full path so navigating away clears the error. app.config.errorHandler in main.js receives what the boundary does not, such as errors in the header's event handlers, logs them in one place and is the hook a reporting service attaches to later. router.onError in main.js catches a failed dynamic import after a deploy, the error whose message names a module or a chunk, and reloads the target location once so the user gets the new build instead of a stuck page.

Then it makes the article page honest. Article.vue's beforeRouteEnter keeps the catch for comments, which may legitimately be empty, but a failed article fetch now sets an error in the article store instead of being ignored, and the view renders a not-found message for a 404 and throws into the boundary for anything else. The e2e suite in realworld/specs/e2e drives the app through the selectors contract the README describes, so the agent checks the fallback markup against the shared theme classes, initialises the submodule as the README says, and runs bun run test:e2e as .github/workflows/playwright.yml does, with Chromium from bunx playwright install --with-deps chromium, plus bun run lint and bun run format:check.

There are no unit tests in the repository, so the agent adds a Playwright spec of its own in a new e2e directory outside the submodule, run through a second config that points at it: it intercepts the article request with page.route to answer 500, opens an article and asserts the fallback and the Try again button, then restores the route, clicks the button and checks the article renders. It runs that spec with the same web server settings and shows the result beside the shared suite.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add error boundaries to this Vue 3 app. Read package.json, src/main.js, src/App.vue, src/router/index.js, src/common/api.service.js, src/common/errors.js, src/components/ListErrors.vue, src/views/Article.vue, src/views/Home.vue, src/store/article.js, playwright.config.ts, the README and the workflows under .github/workflows first, and initialise the realworld submodule. Add an ErrorBoundary component built on onErrorCaptured with a fallback in the RealWorld markup and a Try again button, wrap the router view in it in App.vue keyed by the route path, set app.config.errorHandler in main.js as the single place other errors are logged, and add router.onError that reloads the target location once when a dynamic import fails. Make a failed article fetch set an error in the store and render a not-found message for a 404 or throw into the boundary otherwise, keeping the comments fetch tolerant. Add a Playwright spec outside the submodule, with its own config, that forces the article request to fail, asserts the fallback, restores the route and checks the retry renders the article. Run the shared e2e suite, your spec, lint and the format check as the workflows do, and open a pull request that quotes the Playwright output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds src/components/ErrorBoundary.vue, the new spec and its Playwright config, and changes src/App.vue, src/main.js, src/store/article.js and src/views/Article.vue. No dependency is added and the submodule pointer is untouched.

The description quotes the Playwright output for the shared RealWorld suite and for the new spec, the lint and format checks, and a screenshot of the fallback over the header and footer from the sandbox browser, so a reviewer sees what a visitor would see when the article request fails.

Before merging, a reviewer decides whether the fallback should also offer a link home, whether errorHandler should report to a service now or later, and whether a chunk-load reload should be limited per session rather than per location. Each is a follow-up on the same session, where the submodule and Chromium are already installed.

Run it on every Vue view failing to a blank page

This is a change to hand off from the terminal: one POST /o/{org}/sessions with this prompt and the repository in resources, and the run reads the router and the API wrapper, writes the boundary, runs the shared suite and opens the pull request on its own. The sandbox parks with its disk when the turn ends, so report captured errors to our error tracker as a follow-up wakes it with node_modules, the submodule and Chromium in place.

A team with several Vue apps sends the same body once per repository, one run each, and each run finds that app's own router and views. Give the API key a webhook_url and Rush posts run.completed or run.failed with the session_url when each turn ends. Send a request_id with each body so a retried POST returns the run it already started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

An error boundary is proven by breaking something on purpose and watching the page stay usable, which is slow to do by hand and easy to skip. The agent forces the article request to fail in its own browser, checks the fallback and the retry, and runs the shared RealWorld suite so the normal paths are shown unchanged, and the pull request carries that output.

The record keeps the choices: the transcript has the agent reading that Article.vue swallowed load failures, deciding which failures should reach the boundary and which should show a not-found message, and checking the fallback against the theme classes the suite's selectors expect. A reviewer who wants a different split says so and the parked sandbox changes the view.

Frequently asked questions

Is onErrorCaptured the same as a React error boundary?

Close. It catches errors from the component's descendants during render, setup, watchers and lifecycle hooks, and returning false stops them from propagating further. The fallback and the retry are ordinary template code around it.

What does the global errorHandler add?

A single place for errors the boundary does not see, such as a handler in the header outside the router view, and the hook where a reporting service is attached later. The boundary returns false so an error is not logged twice.

Which errors are not caught?

A rejected promise nobody awaits, and errors in code outside the component tree. The API wrapper's rejections are awaited in the views and stores, so they reach the boundary or the not-found message, and the description says where an unhandledrejection listener would go.

Will the RealWorld e2e suite still pass?

Yes. The fallback uses the theme's own container classes and only renders when something throws, and the agent runs the whole suite as playwright.yml does before opening the pull request.

Why reload on a chunk error?

Because after a deploy the old page may ask for a chunk that no longer exists, and the only fix is the new build. router.onError recognises that error, reloads the target location once, and leaves other navigation errors to the boundary.

More Vue jobs

The same job on other stacks

Keep reading