refactor(release-cleanup): 收斂錯誤輸出並抽出驗證規則常數
- 新增 logger.failError 集中處理 Error/非 Error 的 stderr 輸出與堆疊, index.js 改用之,移除重複的 reportFatal - validate.js 將允許協定與 repository 格式抽為模組常數,便於維護擴充 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
0f4354bd01
commit
f6d2ebeab2
@@ -51,3 +51,20 @@ export function warn(message) {
|
||||
export function fail(message) {
|
||||
process.stderr.write(`[ERR] ${message}\n`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 輸出錯誤至 stderr,並依錯誤型別保留可供除錯的上下文:
|
||||
* 若為 Error 物件,輸出「名稱: 訊息」並附上堆疊;否則輸出其字串形式。
|
||||
* 將「如何輸出錯誤」的邏輯集中於此,呼叫端毋須自行操作 stderr 或判斷型別。
|
||||
* @param {unknown} error 待輸出的錯誤
|
||||
*/
|
||||
export function failError(error) {
|
||||
if (error instanceof Error) {
|
||||
fail(`${error.name}: ${error.message}`)
|
||||
if (error.stack) {
|
||||
process.stderr.write(`${error.stack}\n`)
|
||||
}
|
||||
} else {
|
||||
fail(String(error))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user