Skip to content

Commit 45c17d5

Browse files
committed
refactor: error-handle
1 parent 13cb286 commit 45c17d5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/setup/lib/error-handle.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @description
3+
* Something do for Error handle
4+
*
5+
* @param {unknown} error Error Object
6+
* @returns {void}
7+
*/
8+
export default function ErrorHandle(error: unknown): void {
9+
if (error instanceof Error) {
10+
console.error('❌ Error:', error.message);
11+
12+
if (error.stack) {
13+
console.error('Stack trace:', error.stack);
14+
}
15+
} else if (typeof error === 'string') {
16+
console.error('❌ Error:', error);
17+
} else {
18+
console.error('❌ Unknown error occurred:', error);
19+
}
20+
21+
process.exit(1);
22+
}
23+
24+
/**
25+
* @description
26+
* Log the error and decide whether to continue
27+
*
28+
* @param {unknown} error Error Object
29+
* @param {string} context Error context
30+
* @returns {boolean} Whether to continue
31+
*/
32+
export function logErrorAndContinue(error: unknown, context?: string): boolean {
33+
const prefix = context ? `[${context}]` : '';
34+
35+
if (error instanceof Error) {
36+
console.warn(`⚠️ ${prefix} Warning:`, error.message);
37+
} else if (typeof error === 'string') {
38+
console.warn(`⚠️ ${prefix} Warning:`, error);
39+
} else {
40+
console.warn(`⚠️ ${prefix} Unknown warning:`, error);
41+
}
42+
43+
return true; // 계속 진행
44+
}

0 commit comments

Comments
 (0)