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

raise custom exception for invalid ID #64

Merged
merged 1 commit into from
Jan 1, 2020

Conversation

indirectlylit
Copy link
Contributor

@indirectlylit indirectlylit commented Nov 2, 2019

The current exception is not super helpful:

~/Projects/le/notion-py/notion/client.py in get_block(self, url_or_id, force_refresh)
     81         Retrieve an instance of a subclass of Block that maps to the block/page identified by the URL or ID passed in.
     82         """
---> 83         block_id = extract_id(url_or_id)
     84         block = self.get_record_data("block", block_id, force_refresh=force_refresh)
     85         if not block:

~/Projects/le/notion-py/notion/utils.py in extract_id(url_or_id)
     30             .split("-")[-1]
     31         )
---> 32     return str(uuid.UUID(url_or_id))
     33 
     34 

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/uuid.py in __init__(self, hex, bytes, bytes_le, fields, int, version, is_safe)
    158             hex = hex.strip('{}').replace('-', '')
    159             if len(hex) != 32:
--> 160                 raise ValueError('badly formed hexadecimal UUID string')
    161             int = int_(hex, 16)
    162         if bytes_le is not None:

ValueError: badly formed hexadecimal UUID string

This PR explains what's happening a bit better:

~/Projects/le/notion-py/notion/client.py in get_block(self, url_or_id, force_refresh)
     81         Retrieve an instance of a subclass of Block that maps to the block/page identified by the URL or ID passed in.
     82         """
---> 83         block_id = extract_id(url_or_id)
     84         block = self.get_record_data("block", block_id, force_refresh=force_refresh)
     85         if not block:

~/Projects/le/notion-py/notion/utils.py in extract_id(url_or_id)
     37         return str(uuid.UUID(url_or_id))
     38     except ValueError:
---> 39         raise InvalidNotionIdentifier(input_value)
     40 

InvalidNotionIdentifier: https://www.notion.so/learningequality/

@jamalex
Copy link
Owner

jamalex commented Jan 1, 2020

Nice, thanks.

@jamalex jamalex merged commit fb45820 into jamalex:master Jan 1, 2020
@jamalex
Copy link
Owner

jamalex commented Jan 4, 2020

Now released to PyPI, in version 0.0.25

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