Skip to content
cccskills
FreePublished on GitHub

backend-debugging

Debug backend runtime errors (500s, crashes, unexpected behavior). Use when something is broken at runtime — not for writing new code.

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34 stars(GitHub 34 + cccskills 0)

Run score Not tested

See how to install

Files included (1)

  • SKILL.md3.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Backend Debugging

Step 0 — If it's a regression, check git history first

When the user reports "it worked before X" / "broke after the refactoring" / "used to work" — read the git history of the affected code path before proposing any fix. A defensive try/catch or null check is the wrong opening move on a regression; the bug is almost always something a recent commit dropped (a break, a return, a case arm, a relation in a query).

# Find the commits that touched the failing handler/file:
git log --oneline -20 -- <path/to/handler.ts>

# Diff against the last-known-good state:
git show <commit>:<path/to/handler.ts>
git log -p -5 -- <path/to/handler.ts>

The fix is then "restore what was lost," not "patch around the symptom." Only after you have the diff against the working version should you consider defensive code.

Step 1 — Read the logs

Before reading code, guessing, or querying the database, check the backend logs:

# From the repo root (slot is remembered from ./dev up):
./dev logs backend                # Last 80 lines
./dev logs --tail 200 backend     # More context

# Or read the log file directly:
cat .dev/slot-$(cat .dev/slot)/backend.log

The logs contain full stack traces with file names and line numbers. This tells you exactly what's broken — no guessing needed.

Do not skip this step. Code review without the actual error is guesswork.

Step 2 — Reproduce the error

Confirm the error independently with curl. This isolates whether the problem is backend vs. frontend vs. CORS:

# Login first (adjust credentials as needed):
curl -s -c /tmp/cookies.txt http://localhost:3020/api/auth/login \
  -X POST -H 'Content-Type: application/json' \
  -d '{"email":"...","password":"..."}'

# Hit the failing endpoint:
curl -s -b /tmp/cookies.txt "http://localhost:3020/api/..." | head -50

Replace port 3020 with whatever the current slot uses. Check with ./dev status.

Recognizing CORS errors

If the browser console shows "blocked by CORS policy" but the request returns a valid status code (e.g., 201), the backend works — the browser is rejecting the response. Look for:

  • Hardcoded Access-Control-Allow-Origin headers in the controller that override the global CORS middleware
  • The global CORS config in src/main.ts — in development mode (NODE_ENV !== 'production') it should allow all origins

Step 3 — Go to the error location

The stack trace gives you the exact file and line. Read that code. Common patterns:

"Cannot read properties of undefined (reading 'map')"

A relation wasn't loaded by TypeORM but the mapper assumes it's always present. Fix with optional chaining:

// Before — crashes when relation not loaded:
items.map(x => ...)

// After:
items?.map(x => ...) ?? []

This is especially common when:

  • A findAll query doesn't load the same relations as findOne
  • Eager relations don't cascade through deeply nested joins (e.g., thread → sourceAssignments → source → details → contentChunks)

"Invalid source type" / "Invalid message role"

A mapper's instanceof or switch doesn't cover all cases. Check what the database actually contains:

# Quick database query through the dev stack:
cd ayunis-core-backend
pnpm exec ts-node -r tsconfig-paths/register -e "
import './src/config/env';
import { DataSource } from 'typeorm';
// ... query the relevant table
"

Step 4 — Fix, verify, check logs again

  1. Make the fix
  2. Wait for nest --watch to reload (or check ./dev logs backend for compilation errors)
  3. Re-run the curl command from Step 2
  4. Check ./dev logs backend to confirm no new errors
  5. Load nestjs-hexagonal-backend and run its validation sequence at the level required by the repository's Proportional Workflow.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Query Ayunis deployed-environment telemetry in AppSignal — incidents, occurrence counts and error traces via the `appsignal-cli` binary; structured log attributes (user.id, org.id, nestjs.context, custom metadata) via the v2 logs API. Use when investigating a production/staging incident or log data — NOT for local dev logs (see backend-debugging).

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

Ayunis Core backend specifics — module boundaries, key files, and project conventions. Complements the nestjs-hexagonal-backend skill.

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

Frontend development in ayunis-core. Use when creating, modifying, or debugging frontend code (React, Feature-Sliced Design, API client).

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

Shared test fixtures for backend specs — port mock factories, domain builders, and shared IDs in a per-module testing/ folder. Use when a module's *.use-case.spec.ts files repeat the same mock-repository literal, inline entity construction, or hardcoded UUIDs across files.

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

Analyze Cursor Bugbot PR comments through a root-cause lens: is the finding valid, and is the suggested fix the real fix or a bandaid over a deeper problem? Use when the user asks to check, assess, or triage bugbot comments.

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

Self-review local changes before creating a PR. Use when the user says "review", "review my code", "check my changes", or wants confidence before submitting.

The English summary is being prepared. Showing the original description.

ayunis-core/ayunis-core34Updated Oct 26, 2026

See all skills by ayunis-core

Report a problem with this skill