Skip to content

Added exception handling for UnicodeDecodeError #1533

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aayushkdev
Copy link
Contributor

Fixes #1526

Added exception handling for UnicodeDecodeError and added a catch all exception for load_json_from_file

@aayushkdev aayushkdev force-pushed the issue-#1526 branch 2 times, most recently from a678664 to 02f9a7a Compare April 1, 2025 16:49
Copy link
Member

@AyanSinhaMahapatra AyanSinhaMahapatra left a comment

Choose a reason for hiding this comment

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

@aayushkdev Thanks, but this is not the correct way to do this. See comments.

return json.load(f)
except json.JSONDecodeError:
return
except UnicodeDecodeError as e:
Copy link
Member

Choose a reason for hiding this comment

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

This still creates an exception and this breaks the pipeline run, we need to catch and create a ProjectMessage https://github.com/aboutcode-org/scancode.io/blob/main/scanpipe/models.py#L1399 object to keep these in the /messages/ tab for that project, instead of raising an exception. Check similar invocations elsewhere for how to do this.

Copy link
Member

Choose a reason for hiding this comment

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

Please run a d2d pipeline using the inputs at #1526 (comment), this should create an error message and the pipeline should complete successfully.

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.

BUG: 'utf-8' codec can't decode byte 0x80 in position 8: invalid start byte
2 participants