-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errorToMessage関数追加し、createLoggerの処理を変更して、eslintのルールを1つ採用 #2212
The head ref may contain hidden characters: "errorToMessage\u4F5C\u308B"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ファイル名が変わりました |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** 入力がnullかundefinedの場合エラーを投げ、それ以外の場合は入力をそのまま返す */ | ||
export const ensureNotNullish = <T>( | ||
value: T | null | undefined, | ||
message = "Unexpected nullish value", | ||
): T => { | ||
if (value == null) { | ||
throw new Error(message); | ||
} | ||
return value; | ||
}; | ||
|
||
/** エラーからエラー文を作る */ | ||
export const errorToMessage = (e: unknown): string => { | ||
if (e instanceof Error) { | ||
return `${e.toString()}: ${e.message}`; | ||
} else if (typeof e === "string") { | ||
return `String Error: ${e}`; | ||
} else if (typeof e === "object" && e != undefined) { | ||
return `Object Error: ${JSON.stringify(e).slice(0, 100)}`; | ||
} else { | ||
return `Unknown Error: ${String(e)}`; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
/** Mapから値を取得する。指定したキーが存在しない場合は例外を投げる */ | ||
export const getOrThrow = <K, V>(map: Map<K, V>, key: K) => { | ||
if (!map.has(key)) { | ||
throw new Error(`Key not found: ${key}`); | ||
throw new Error(`Key not found: ${String(key)}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 元のコードだとSymbolが来たときにエラーになってた |
||
} | ||
return map.get(key) as V; | ||
}; | ||
|
||
/** Mapから値を削除する。指定したキーが存在しない場合は例外を投げる */ | ||
export const deleteOrThrow = <K, V>(map: Map<K, V>, key: K) => { | ||
if (!map.has(key)) { | ||
throw new Error(`Key not found: ${key}`); | ||
throw new Error(`Key not found: ${String(key)}`); | ||
} | ||
map.delete(key); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの処理変更によって、console.logだとなんかいい感じに表示される
"%o", 25
のような書式が使えなくなってしまいます。たぶん現コードのどこにも使われてないけれども、この変更していいのかが判断しづらい。。
(テンプレート文字列の方が使いやすい気はする)