-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python API: Improve error handling for messages that failed to parse
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
pagefind/integration_tests/python_api/py-pagefind-error-handling.toolproof.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Python API > Pagefind error handling | ||
platforms: | ||
- linux | ||
- mac | ||
|
||
steps: | ||
- ref: ./background.toolproof.yml | ||
- step: I have a "public/run.py" file with the content {python} | ||
python: |2- | ||
import sys | ||
sys.path.append('%repo_wd%/wrappers/python/src') | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pagefind.index import PagefindIndex, IndexConfig | ||
async def main(): | ||
async with PagefindIndex() as index: | ||
await index.delete_index() | ||
try: | ||
files = await index.get_files() | ||
except AssertionError: | ||
print("Index deleted") | ||
try: | ||
async with PagefindIndex(IndexConfig(root_selector=5)) as index: | ||
await index.delete_index() | ||
except Exception as e: | ||
print(f"Caught error {e}") | ||
print("Complete") | ||
if __name__ == "__main__": | ||
asyncio.run(main()) | ||
- step: I run "cd public && PAGEFIND_BINARY_PATH=%pagefind_exec_path% python3 run.py" | ||
- step: 'stdout should contain "invalid type: integer `5`"' | ||
- step: stdout should contain "Index deleted" |
This file contains 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
a53f3c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code golf: you can keep the
if (message_id := resp.get("message_id") is None: ...; else: ...
structure; the variable created by the walrus operator will be available in both branches.Here's an example:
a53f3c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm not sure if I follow in context — I want the main
if
branch to run if there is amessage_id
at either the root or in the original message, so was avoiding duplicating some of the future logic into anelse:
branch.Might be missing something though! I'm not particularly fluent here 😄 Feel free to jump in and clobber over anything I have done! This handling is specifically covered by one of the Toolproof tests so as long as that passes I'm happy ☺