| name | good-debug |
| description | Use when encountering a bug, unexpected behavior, or error in the frontend - before attempting any fix |
Good Debug
์ฆ์์ด ์๋ ์์ธ์ ์์ ํ๋ค. ์๋ฌ๋ฅผ ์จ๊ธฐ๊ฑฐ๋ ์ฐํํ์ง ์๋๋ค.
๋๋ฒ๊น
4๋จ๊ณ
1. ์ง๋จ โ ๋ฌด์์ด ๋ฌธ์ ์ธ์ง ์ ํํ ํ์
์๋ฌ ๋ฉ์์ง๋ฅผ ์ฒซ ์ค๋ง ๋ณด์ง ๋ง๊ณ ์ ์ฒด๋ฅผ ์ฝ๋๋ค.
| ์๋ฌ ์ข
๋ฅ | ํ์ธ ํฌ์ธํธ |
|---|
SyntaxError | ๊ดํธ/๋ฐ์ดํ ๋ถ์ผ์น, ์๋ชป๋ ํค์๋ |
TypeError | ๊ฐ์ฒด๊ฐ undefined์ธ๋ฐ ์ ๊ทผ, await ๋๋ฝ |
ReferenceError | ๋ณ์ ์ ์ธ ์์น, ์ค์ฝํ |
| ๋คํธ์ํฌ ์๋ฌ | CORS, ์ธ์ฆ, 4xx vs 5xx ๊ตฌ๋ถ |
| ๋ชจ๋ ์๋ฌ | ESM vs CommonJS, ๊ฒฝ๋ก, ํ์ฅ์ |
์๋ฌ ๋ฉ์์ง๋ฅผ ํต์งธ๋ก ๊ฒ์ํ๊ธฐ ์ ์: ๋ฌด์จ ์๋ฏธ์ธ์ง โ ์ด๋ค ์ํฉ์ธ์ง โ ๊ฐ๋ฅํ ์์ธ์ ์์๋๋ก ์๊ฐํ๋ค.
2. ์ฌํ โ ์ฌํ ์ ๋๋ฉด ๊ณ ์น ์ ์๋ค
์ฌํ ์กฐ๊ฑด์ ์ต์ํํ๋ค. ๊ด๋ จ ์๋ ๋น๋๊ธฐ ์ฒ๋ฆฌ, ์ํ ๊ด๋ฆฌ, UI๋ฅผ ์ ๊ฑฐํ๊ณ ํต์ฌ ๋ก์ง๋ง ๋จ๊ธด๋ค.
const result = calculateDiscount(price, coupon);
console.log(result);
ํน์ ๋ฐ์ดํฐ/์ํ์์๋ง ๋ฐ์ํ๋ฉด ๊ทธ ์กฐ๊ฑด์ ๊ณ ์ ํ๋ค. ์ฌํ์ด ๋น ๋ฅผ์๋ก ์์ธ ํ์
๋ ๋น ๋ฅด๋ค.
3. ์์ โ ๊ทผ๋ณธ ์์ธ์ ๊ณ ์น๋ค
์ฆ์๋ง ๊ณ ์น๋ฉด ๋ฒ๊ทธ๋ ๋ค๋ฅธ ํํ๋ก ๋ค์ ๋ํ๋๋ค.
const user = selectedUser as User;
const name = selectedUser!.name;
if (!selectedUser) throw new Error("selectedUser is required");
const name = selectedUser.name;
setTimeout(() => refetch(), 300);
const controller = new AbortController();
fetch(url, { signal: controller.signal });
๋น์ฆ๋์ค ๋ก์ง์ ์์ ํจ์๋ก ๋ถ๋ฆฌํ๋ฉด ๋
๋ฆฝ์ ์ผ๋ก ํ
์คํธํ ์ ์๊ณ , ๊ฐ์ ๋ฒ๊ทธ๊ฐ ์ฌ๋ฐํ๋ฉด ํ
์คํธ๋ก ์ก์ ์ ์๋ค.
4. ์ฌ๋ฐ ๋ฐฉ์ง
- ๊ณ ์น ์กฐ๊ฑด๊ณผ ๊ฐ์ ์กฐ๊ฑด์์ ๋ค์ ์ฌํ ์๋ํด์ ๊ฒ์ฆ
- ์ฃ์ง ์ผ์ด์ค(๋น ๋ฐฐ์ด, null, ์ต๋๊ฐ ๋ฑ)๋ ํ์ธ
- ๊ฐ์ ํจํด์ ๋ฒ๊ทธ๊ฐ ๋ค๋ฅธ ๊ณณ์ ์์ง ์์์ง ํ์
์ฃผ์ ๋๋ฒ๊น
๋๊ตฌ
| ์ํฉ | ๋๊ตฌ |
|---|
| ์ปดํฌ๋ํธ ์ํ | React DevTools |
| ์๋ฒ ์ํ / ์บ์ฑ | React Query Devtools |
| ๋ผ์ฐํ
๋ฌธ์ | TanStack Router Devtools |
| ๋คํธ์ํฌ ์์ฒญ | ๋ธ๋ผ์ฐ์ Network ํญ |
| ๋ฒ๋ค/๋น๋ ์๋ฌ | pnpm --filter front build |
| ํ์
์๋ฌ | pnpm --filter front build (tsc ํฌํจ) |
ํ์ง ๋ง ๊ฒ
// @ts-ignore ๋ก ํ์
์๋ฌ ๋ฌด์
try { } catch(e) {} ๋น catch
- ์์ธ ๋ชจ๋ฅด๊ณ
key ๋ฐ๊ฟ์ ๋ฆฌ๋ ๋๋ง ๊ฐ์
! (non-null assertion) ๋จ์ฉ
setTimeout์ผ๋ก ํ์ด๋ฐ ๋ฌธ์ ์์ ํด๊ฒฐ