fix: remove leftover console.log(error) in lib/user-data.ts#488
fix: remove leftover console.log(error) in lib/user-data.ts#488narutamaaurum wants to merge 2 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
👋 Thanks for opening a PR, @narutamaaurum!Your PR has entered the 🚦 PR Review Pipeline.
What happens next
A pipeline status comment will appear below and update automatically as your PR progresses. While you wait
This comment is posted only once. |
WalkthroughAdds a structured ChangesError handling updates in lib/user-data.ts
Sequence Diagram(s)(no sequence diagrams generated) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/user-data.ts`:
- Line 12: The three Prisma helper functions getUserById, getUserByEmail, and
getAccountByUserId currently swallow all errors with parameterless catches;
change each catch to capture the error (e.g., catch (err)) and either log the
error via the app logger (structured if available) with contextual info
(function name and query params) or rethrow it so higher layers can handle it;
also ensure you only return null for genuine “not found” results (let the query
resolve to null) and treat thrown errors as failures, not missing records, so
auth logic can differentiate DB failures from absent users.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 861a392e-93f5-4d58-835f-b3ea96ceb229
📒 Files selected for processing (1)
lib/user-data.ts
- Replace bare catch blocks with proper error capture and structured logging - Log errors with function name and query parameters for observability - Rethrow errors so callers can differentiate DB failures from not-found results - Follow existing structured logging pattern from lib/api-utils.ts Addresses CodeRabbit review on PR piyushdotcomm#488
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/user-data.ts`:
- Around line 3-14: The logs currently include raw params in logError, causing
emails to be written when getUserByEmail fails; update logging to redact PII by
either (A) adding a small sanitizer function (e.g., redactParams or maskPII)
that detects and masks common sensitive keys like "email", "phone", "ssn" and
use it inside logError before stringifying params, or (B) call
redactParams(getUserByEmailParams) when invoking logError from getUserByEmail;
reference the existing logError function and getUserByEmail call sites and
ensure the masked object (not the original) is what gets logged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e5caee58-926d-458b-855f-6549dbefc1e9
📒 Files selected for processing (1)
lib/user-data.ts
| const logError = (functionName: string, params: Record<string, unknown>, error: unknown) => { | ||
| console.error( | ||
| JSON.stringify({ | ||
| timestamp: new Date().toISOString(), | ||
| level: "error", | ||
| context: functionName, | ||
| params, | ||
| error: error instanceof Error ? error.message : "Unknown error", | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| }) | ||
| ); | ||
| }; |
There was a problem hiding this comment.
Consider redacting PII before logging.
The params object is logged directly, which means email addresses will appear in logs when getUserByEmail fails (line 38). Logging user emails can create compliance issues under GDPR/CCPA and increases data breach risk.
Consider masking sensitive fields:
🛡️ Proposed fix to mask email
const logError = (functionName: string, params: Record<string, unknown>, error: unknown) => {
+ // Mask sensitive fields before logging
+ const safeParams = { ...params };
+ if (typeof safeParams.email === 'string') {
+ safeParams.email = safeParams.email.replace(/(.{2})(.*)(@.*)/, '$1***$3');
+ }
console.error(
JSON.stringify({
timestamp: new Date().toISOString(),
level: "error",
context: functionName,
- params,
+ params: safeParams,
error: error instanceof Error ? error.message : "Unknown error",
stack: error instanceof Error ? error.stack : undefined,
})
);
};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@lib/user-data.ts` around lines 3 - 14, The logs currently include raw params
in logError, causing emails to be written when getUserByEmail fails; update
logging to redact PII by either (A) adding a small sanitizer function (e.g.,
redactParams or maskPII) that detects and masks common sensitive keys like
"email", "phone", "ssn" and use it inside logError before stringifying params,
or (B) call redactParams(getUserByEmailParams) when invoking logError from
getUserByEmail; reference the existing logError function and getUserByEmail call
sites and ensure the masked object (not the original) is what gets logged.
|
Created PR #489 with the PII redaction fix for the CodeRabbit review comments. |
Closes #274
Removes three leftover debugging statements from in the catch blocks of:
These were debug logs that are no longer needed. The functions already return on error, which is the proper error handling.
Summary by CodeRabbit