Include offending ingredient text in the too-long parse error - #4832
Open
Themazecrawler wants to merge 1 commit into
Open
Themazecrawler wants to merge 1 commit into
Themazecrawler wants to merge 1 commit into
Conversation
Previously the error just said an ingredient exceeded 512 characters with no indication which one, making it hard to track down during a recipe import when none of the source ingredients look that long (e.g. when strings get concatenated somewhere upstream). Now the message includes the first 100 characters of the offending string, which reaches the user directly since integration.py surfaces str(e) in the import log. Fixes TandoorRecipes#4790
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The ingredient parser rejects anything over 512 characters, but the error it raises doesn't say ingredient triggered it. That's confusing during an import where none of the source ingredients actually look that long (see #4790, someone hitting this on a Mealie import with no obviously long ingredients).
I traced where the message actually ends up: in
cookbook/integration/mealie1.pythe call toingredient_parser.parse()isn't wrapped in a try/except, so theValueErrorbubbles up tointegration.py, which doesstr(e)straight into the import log the user sees. So whatever we put in the message is what they get.Now the message includes the first 100 characters of the string that was too long, so at least a truncated version of the offending ingredient shows up in the log instead of a bare "too long" with no context.
Fixes #4790
Test plan
pytest cookbook/tests/other/test_ingredient_parser.pypasses (3 passed)