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

don't panic when unmarshaling blocks #50

Merged
merged 3 commits into from
Feb 21, 2023
Merged

Conversation

bassettb
Copy link
Contributor

This library shouldn't panic when it encounters an unsupported block type. Just omit that block from the returned blocks.

@bassettb
Copy link
Contributor Author

@dstotijn

@bassettb
Copy link
Contributor Author

@dstotijn please

@dstotijn
Copy link
Owner

dstotijn commented Feb 6, 2023

I agree that blockDTO.Block() shouldn't panic when an unsupported block type is encountered. But I wouldn't return a nil value and silently drop it in list responses. This could lead to unexpected/confusing behavior for users of the library.

I would rather change the signature of the Block method to func Block() (Block, error), and bubble up the error at all the call sites where Block is called. This will be a breaking change, but that's fine (we're at v0).

@bassettb Let me know if you want to make the aforementioned change on this PR, otherwise I can do it.

@bassettb
Copy link
Contributor Author

bassettb commented Feb 7, 2023

I agree that it's not an ideal solution. But unsupported blocks are extremely common. They are built into the API (type="unsupported"). And this package might be slow to support new types. Callers of FindBlockChildrenByID would rather get the supported blocks than get no blocks just because of a single unsupported block.

@bryan-fs
Copy link

I updated the PR so that other callers of Block() can receive and handle any errors.

@dstotijn dstotijn merged commit c6f2e5b into dstotijn:main Feb 21, 2023
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.

3 participants