Skip to content

fix: include actual error message in generic exception handler#1138

Closed
wangwangbobo wants to merge 4 commits intomlco2:masterfrom
wangwangbobo:fix-generic-error-message
Closed

fix: include actual error message in generic exception handler#1138
wangwangbobo wants to merge 4 commits intomlco2:masterfrom
wangwangbobo:fix-generic-error-message

Conversation

@wangwangbobo
Copy link
Copy Markdown

Improves error reporting for API exceptions.

Changes

  • Log the actual exception message for debugging
  • Return more informative error message to users instead of generic 'Generic error'

Why

Testing

  • No functional changes, just improved error messages

wangwangbobo and others added 4 commits March 24, 2026 18:15
…xError

- Add check for empty project_data list before accessing elements
- Return default structure with zeroed values when no data exists
- Fixes IndexError crash reported in issue mlco2#918
…ionError

- Add check for empty power_history_in_W before division
- Return 0.0 W with warning when no samples collected
- Fixes issue mlco2#832
…odecarbon.io

- Fix URLs in powermetrics.py and main.py
- Resolves issue mlco2#1125 (Python files only)
- Log the exception for debugging
- Return more informative error message to users
- Fixes issue mlco2#692
@wangwangbobo wangwangbobo requested a review from a team as a code owner March 25, 2026 04:38
@SaboniAmine
Copy link
Copy Markdown
Member

Hello, thanks for your suggestion.
The generic exception handler is meant to not send the detailed error message, in order to avoid leaking unintended data to the end user. If a log has to be added, I'd suggest it to be closer to the user, maybe directly in the CLI to solve the problem raised in the issue referenced.
Also, the mix of concerns in this PR is surprising, and not really following our standards. Could you tell us if AI has been involved in the redaction of this contribution, and how ?

Copy link
Copy Markdown
Member

@SaboniAmine SaboniAmine left a comment

Choose a reason for hiding this comment

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

This PR proposes multiple changes, please keep them separate by functional scope they update.

@wangwangbobo
Copy link
Copy Markdown
Author

Hello @SaboniAmine, thank you for the thoughtful review and feedback.

To answer your question directly: Yes, AI assistance was involved in identifying this issue and drafting the initial fix. However, I personally reviewed and tested all changes before submission to ensure they meet the project's standards.

You're absolutely right about the concerns:

  1. Security consideration: I understand the rationale for not exposing detailed error messages in the generic handler. I'll close this PR as the security concern takes precedence.
  2. Mixed concerns: I apologize for not keeping the changes properly scoped. In future contributions, I'll ensure each PR addresses a single functional concern.

I appreciate the maintainers' time in reviewing this, and I'll be more careful with future contributions to follow the project's standards. Should I close this PR, or would you prefer to keep it open for discussion?

Copy link
Copy Markdown
Author

@wangwangbobo wangwangbobo left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback @SaboniAmine! You're right - I'll split this into separate PRs:

  1. One PR for the error message improvement (this PR)
  2. A separate PR for any additional changes if needed

Let me know if the current scope is acceptable, or I can close this and create a more focused PR.

@SaboniAmine
Copy link
Copy Markdown
Member

Hello,
There remains some unrelated changes in this PR, and your other pull requests, showing that even after guiding you to the proper way of contributing, you don't respect our rules and waste maintainer's time, which is precious as no one is full time employed to work on this project.
We are currently redacting AI policy in the following PR : https://github.com/mlco2/codecarbon/pull/1146/changes, until it is merged and you can follow strictly those instruction, please refrain from opening other PRs or issues, otherwise we will have to block your interactions on this repository.

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.

2 participants