Skip to content
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

Fix: reason return on rest api error #757

Merged
merged 4 commits into from
Feb 18, 2024
Merged

Conversation

bigredfrog
Copy link
Contributor

@bigredfrog bigredfrog commented Feb 18, 2024

As per sentry example

https://ledfx-org.sentry.io/issues/4985345081/?project=4506350233321472&query=release%3Aledfx%402.0.93&referrer=release-issue-stream

If the reason return is complex, the json serialisation in the rest call response can fail.

In this case, setting min freq to 0 by typing in device edit and directly hitting save allows an out of range return

The reason is an object and existing code would pass that on, leading to a generic error in the front and a report back into sentry

This fix hardens the handling of reason when found, and ensures conversion to string

Tested by forcing the zero value in min freq and hitting save, now reports correct reason string to front end. No crash trace triggered in console

Note call to repr(e) was replaced with str(e) due to advice from chatgpt. quoting...

Use of str() Over repr(): While repr(e) is also a string, str(e) is generally more user-friendly and intended for end-user display. This change makes the error message more suitable for inclusion in a JSON response intended for client applications.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling by ensuring error reasons are correctly converted to strings for clearer messaging.

Copy link
Contributor

coderabbitai bot commented Feb 18, 2024

Walkthrough

The update is a minor yet crucial enhancement focusing on improving error handling within the system. It specifically adjusts how error reasons are processed, ensuring that they are consistently converted to strings. This change aids in standardizing the error logging or handling mechanism, making it easier to understand and diagnose issues by ensuring error messages are always in a readable and expected format.

Changes

Files Change Summary
ledfx/api/__init__.py Convert reason variable to string for reason[0] and e.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a664f6a and 6d892f8.
Files selected for processing (1)
  • ledfx/api/init.py (1 hunks)
Additional comments: 2
ledfx/api/__init__.py (2)
  • 65-65: Converting reason[0] to a string using str() is a good practice for ensuring that the error message is serializable and user-friendly. This change aligns with the PR's objective to improve error handling by making error messages more comprehensible to end-users.
  • 67-67: Similarly, converting the exception e to a string using str() is a positive change. It ensures that exceptions are handled gracefully and that error messages are suitable for display in client applications, enhancing the user experience by providing clearer error information.

@shauneccles shauneccles merged commit d310d96 into LedFx:main Feb 18, 2024
20 checks passed
@bigredfrog bigredfrog deleted the fix_reason branch February 19, 2024 01:37
shauneccles pushed a commit to shauneccles/LedFx that referenced this pull request Feb 23, 2024
* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls
shauneccles added a commit that referenced this pull request Feb 23, 2024
* feat: Expose melbank configurations via API

* Remove melbanks API endpoint and fix melbanks config population

* Expose audio analysis methods via API

* Update sentry-sdk to be >=

* build: refactor sentry init, refactor spec files, wheel workflow, add sha and release to info.py

* Change audio frame size mismatch logging level to debug

* Add saturation threshold to Glitch effect

* Fix error message return for trying to create a device with existing ip

* Add BaseConfigUpdateEvent and handle base configuration updates

* Add websocket docs and capture _sender connection reset errors.

* Update incorrect docstring

* Add handling for non-subscribable events in WebsocketConnection

* chore(deps): update dependency pytest to v8.0.1

* Add automated update checker with notifications and API endpoint

* Use slicing for saturation clipping and add option for fixing hues in HSV effect

* Fix: reason return on rest api error (#757)

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* Fix handling of complex reason failures on rest calls

* fix(deps): update dependency python-mbedtls to v2.9.2

* Fix: remove redundant melbank NaN clean (#755)

* Update dependency pre-commit to v3.6.2

* Fix DDP connections error to warn once

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update dependency sentry-sdk to v1.40.5

* Add event firing for device deactivation from errors and error recovery

* Fix openrgb device type

* Move renovate to .github and enable automerge for minor/patch updates

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/asottile/pyupgrade: v3.15.0 → v3.15.1](asottile/pyupgrade@v3.15.0...v3.15.1)

* Update renovate.json with additional helpers

* Fix renovate config

* Remove gha digests from renovate

* Initial addition of frontend source

* Remove electron/storybook options

* Update branding and remove references to hacking

* Remove automatic starring of repos

* Further removal of starring

* Update websocket event names

* Add LedFx to sidebar

* Use backend update checker to check and notify for updates

* Remove additional electron artifacts

* Rebuild frontend and add deploy scripts

* Update documentation and re-add frontend development setup

* Release 2.0.94

* Add frontend-ci to validate frontend changes

* Update frontend-ci.yml to install NPM packages in the frontend directory

* Update Yarn to v1.22.21

* Add frontend directory to build step

* Update dependency eslint-plugin-import to v2.29.1

* Update dependency strip-ansi to v7

* Update dependency ts-deepmerge to v7

* Update dependency base32-encode to v2

* Fix conditional check for openRGB devices

* Update CI/CD workflows to reduce action usage and prevent early sentry notifications

* Add environment for approval prior to release creation/publishing

* Update typescript-eslint monorepo to v7

* Update storybook monorepo to v7.6.17

* Update dependency eslint to v8.56.0

* Update preset categories in store and API

* Update frontend/src/components/Dialogs/SceneDialogs/EditSceneDialog.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Slight cleanup of names and hooks

* Fix ledfx_presets array indexing

* Handle multiple enums from audio schema, fix linting and remove tempo_method

---------

Co-authored-by: atod <anthony.tod@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Christian W. Zuckschwerdt <christian@zuckschwerdt.org>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

None yet

2 participants