Skip to content

Use warn for user induced errors.#282

Merged
PierreLeGuen merged 3 commits intomainfrom
fix/log-levels
Dec 17, 2025
Merged

Use warn for user induced errors.#282
PierreLeGuen merged 3 commits intomainfrom
fix/log-levels

Conversation

@Evrard-Nil
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 17, 2025 13:05
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Evrard-Nil, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refines the application's logging strategy by reclassifying several log messages from error! to warn!. The primary goal is to improve the clarity and actionability of logs by distinguishing between critical system failures and issues that stem from user-induced conditions, such as malformed requests, invalid parameters, or attempts to access unauthorized resources. This change helps reduce noise in error logs, allowing developers to focus on more severe operational problems.

Highlights

  • Refined Logging Levels: Changed numerous error! log statements to tracing::warn! for issues that are considered user-induced or client-side errors, rather than critical server failures.
  • Consistent Tracing Usage: Ensured consistent use of tracing::warn! across the codebase for these reclassified warnings, aligning with the tracing framework.
  • Conditional Error Logging for File Operations: Implemented a more granular logging approach for file service errors, where client-side errors (e.g., NotFound, FileTooLarge) are logged as tracing::warn!, while true server-side errors remain tracing::error!.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@claude
Copy link

claude bot commented Dec 17, 2025

Code Review

This PR appropriately changes logging levels from error! to warn! for user-induced errors, which aligns with the project's logging guidelines in CLAUDE.md. The implementation looks solid overall.

✅ Strengths

  1. Appropriate log level distinction: Client errors (4xx) logged as warn, server errors (5xx) as error - this is the correct pattern
  2. Privacy-safe error messages: The FileServiceError Display implementations don't expose sensitive data (file contents, etc.)
  3. Consistent pattern: The status code checking pattern is applied uniformly across file operations

No Critical Issues Found

All changes are appropriate:

  • User authentication failures → warn
  • Invalid OAuth states → warn
  • Missing User-Agent headers → warn
  • File operation validation errors → warn
  • Organization/workspace not found → warn

The conditional logging in files.rs (lines 232-237, 427-432, 507-512, 595-600) properly differentiates between client and server errors before logging.

Minor Observation (Non-blocking)

In organization_members.rs:347, the change uses warn! instead of tracing::warn!. While both work (assuming warn is imported from tracing), the rest of the PR uses tracing::warn! for consistency. This is a style preference, not a functional issue.


Approved - No critical issues. Ready to merge.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly changes the log level from error to warn for user-induced errors, which is a great improvement for log clarity and monitoring. The changes are applied consistently across several files. I've added one suggestion to refactor duplicated error-handling logic in crates/api/src/routes/files.rs to enhance maintainability. Overall, this is a solid contribution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the logging strategy by changing error-level logs to warning-level logs for user-induced errors (4xx client errors), while keeping error-level logs for server errors (5xx). This follows best practices where error! logs indicate issues requiring immediate attention from developers, while warn! logs indicate expected conditions like invalid user input.

  • Changes direct error! macro calls to tracing::warn! for client errors across authentication, authorization, and resource access scenarios
  • Introduces conditional logging in the files module that dynamically chooses log level based on HTTP status code
  • Maintains error! logs for genuine server-side failures

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/api/src/routes/users.rs Changes token rotation failure from error to warning
crates/api/src/routes/organizations.rs Changes organization not found errors to warnings
crates/api/src/routes/organization_members.rs Changes invalid member removal params to warning
crates/api/src/routes/files.rs Implements conditional logging pattern based on status code, with client errors as warnings and server errors remaining as errors
crates/api/src/routes/auth.rs Changes OAuth callback and NEAR authentication validation failures to warnings
crates/api/src/middleware/body_hash.rs Changes request body reading failure to warning
crates/api/src/middleware/auth.rs Changes authentication/authorization failures (admin privileges, API key issues, workspace not found) to warnings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)),
Err(OrganizationError::InvalidParams(msg)) => {
error!("Cannot remove member: {}", msg);
warn!("Cannot remove member: {}", msg);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro invocation style is inconsistent across the codebase. This file uses warn! (relying on the import), while most other files in this PR use tracing::warn! (fully qualified path). For consistency, either use warn! everywhere (and ensure the import is present) or use tracing::warn! everywhere. The recommended approach is to use the fully qualified tracing::warn! to match the pattern used in the majority of changes in this PR.

Suggested change
warn!("Cannot remove member: {}", msg);
tracing::warn!("Cannot remove member: {}", msg);

Copilot uses AI. Check for mistakes.
@Evrard-Nil Evrard-Nil temporarily deployed to Cloud API test env December 17, 2025 13:26 — with GitHub Actions Inactive
@PierreLeGuen PierreLeGuen merged commit 9fe4b88 into main Dec 17, 2025
1 check passed
@PierreLeGuen PierreLeGuen deleted the fix/log-levels branch December 17, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants