Files
2nd/10_Wiki/Topic_Programming/DevOps_and_Security/Issue-001-Combat-Reference-Error-Troubleshooting.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

4.7 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-issue-001-combat-reference-error Issue 001 Combat Reference Error Troubleshooting 10_Wiki/Topics verified self
Reference Error Debugging
Runtime Reference Error
none B 0.85 applied
debugging
reference-error
runtime
troubleshooting
combat-system
2026-05-10 pending
language framework
typescript nodejs

Issue 001 Combat Reference Error Troubleshooting

매 한 줄

"매 ReferenceError 의 root cause 매 hoisting, TDZ, circular import, async timing 의 4 가지로 collapse". 매 case study (combat system 의 reference error) 를 통해 매 systematic debug pipeline 정리.

매 핵심

매 ReferenceError 4 카테고리

  • Undeclared: variable 매 declare 안됨 (typo, missing import).
  • TDZ: let/const 매 init 전 access (temporal dead zone).
  • Circular import: A imports B, B imports A → 매 partially-loaded module.
  • Async timing: top-level await, dynamic import 의 race.

매 Combat case (post-mortem 요약)

  • Symptom: ReferenceError: CombatEngine is not defined 매 production only.
  • Root cause: Vite tree-shaking 의 side-effect import 의 elimination.
  • Fix: package.json"sideEffects": ["./src/combat/registry.ts"].

매 Debug 절차

  1. Reproduce: minimal repo.
  2. Stack trace: 매 first frame 의 file:line.
  3. Bisect: git bisect or feature flag.
  4. Verify: regression test 추가.

💻 패턴

TDZ 의 detection

// BAD — TDZ
console.log(x); // ReferenceError
let x = 1;

// GOOD — declare 먼저
let x: number;
x = 1;
console.log(x);

Circular import resolve

// a.ts
import { B } from './b';
export class A { b = new B(); }

// b.ts — circular
// import { A } from './a';  // 매 X
// 매 type-only import 로 break:
import type { A } from './a';
export class B { parent?: A; }

Vite sideEffects 의 protect

// package.json
{
  "sideEffects": [
    "./src/combat/registry.ts",
    "./src/polyfills/*.ts",
    "*.css"
  ]
}

Webpack module federation 의 안전한 dynamic

const Combat = await import(/* webpackChunkName: "combat" */ './combat')
  .catch(err => {
    console.error('Combat module failed', err);
    return { CombatEngine: class FallbackEngine {} };
  });

Stack trace parser

function parseRefError(err: Error): { name: string; file?: string; line?: number } {
  const m = err.message.match(/(\w+) is not defined/);
  const frame = err.stack?.split('\n')[1]?.match(/at .* \((.+):(\d+):\d+\)/);
  return {
    name: m?.[1] ?? 'unknown',
    file: frame?.[1],
    line: frame ? Number(frame[2]) : undefined
  };
}

Regression test

import { describe, it, expect } from 'vitest';
import { CombatEngine } from '@/combat';

describe('combat module loading', () => {
  it('exports CombatEngine after tree-shake', () => {
    expect(CombatEngine).toBeDefined();
    expect(typeof CombatEngine).toBe('function');
  });

  it('registry has registered abilities', async () => {
    const { abilityRegistry } = await import('@/combat/registry');
    expect(abilityRegistry.size).toBeGreaterThan(0);
  });
});

Sentry breadcrumb 의 capture

import * as Sentry from '@sentry/node';
Sentry.init({
  beforeSend(event, hint) {
    if (hint.originalException instanceof ReferenceError) {
      event.tags = { ...event.tags, error_class: 'reference' };
    }
    return event;
  }
});

매 결정 기준

상황 Approach
TDZ 의 의심 매 declaration 위치 의 audit
Circular import type-only import or DI
Tree-shake elimination sideEffects 명시
Async race top-level await guard

기본값: 매 minimal repro → bisect → regression test 의 add.

🔗 Graph

🤖 LLM 활용

언제: stack trace + module graph paste → root cause hypothesis. 언제 X: 매 production memory dump 매 직접 read X — local repro 가 우선.

안티패턴

  • Catch and ignore: try { ... } catch {} — error 매 silently 사라짐.
  • No regression test: fix 후 test 매 추가 X → 매 regression repeat.
  • Random side-effect import: import './magic' — tree-shake 가 죽임.
  • Production-only debug: local 매 repro 안하고 prod 에서 console.log.

🧪 검증 / 중복

  • Verified (MDN ReferenceError, Vite tree-shake docs).
  • 신뢰도 B (case-specific 의 detail).

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — ReferenceError 의 4 카테고리 + combat case