-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 [Code Health] Fix swallowed errors in validators.ts catch blocks #349
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||
| import { logger } from "./logger"; | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Validates a GitHub username. | ||||||||||||||||||
| * Rules: | ||||||||||||||||||
|
|
@@ -64,8 +65,8 @@ function getTrustedFontOrigins(): Set<string> { | |||||||||||||||||
| if (configuredOrigin.startsWith("https://")) { | ||||||||||||||||||
| origins.add(configuredOrigin); | ||||||||||||||||||
| } | ||||||||||||||||||
| } catch { | ||||||||||||||||||
| // Ignore invalid deployment configuration and fall back to the fixed allowlist. | ||||||||||||||||||
| } catch (err) { | ||||||||||||||||||
| logger.warn("Invalid APP_URL deployment configuration. Falling back to fixed allowlist.", err); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -121,7 +122,8 @@ export function isTrustedFontUrl(url: string, allowedOrigin?: string): boolean { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return false; | ||||||||||||||||||
| } catch { | ||||||||||||||||||
| } catch (err) { | ||||||||||||||||||
| logger.warn("Invalid URL provided to isTrustedFontUrl.", err); | ||||||||||||||||||
| return false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+125
to
128
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. Logging a warning for every invalid URL passed to It is recommended to revert this change for } catch {
return false;
}
Comment on lines
+125
to
128
Contributor
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.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/lib/validators.ts
Line: 125-128
Comment:
`isTrustedFontUrl` の catch ブロックは `new URL(url)`(101行目)と `new URL(allowedOrigin)`(115行目)の両方で発生した例外を捕捉します。現在のログメッセージ `"Invalid URL provided to isTrustedFontUrl."` は `url` が不正であるかのように読めますが、`allowedOrigin` が不正な場合も同じメッセージが出力されます。どちらのパラメータが原因かをデバッグ時に把握しやすくするため、より具体的なメッセージにすると良いでしょう。
```suggestion
} catch (err) {
logger.warn("Invalid URL provided to isTrustedFontUrl (url or allowedOrigin is malformed).", err);
return false;
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||
| } | ||||||||||||||||||
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.
Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!