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

Make usable as library #116

Closed
wants to merge 4 commits into from
Closed

Make usable as library #116

wants to merge 4 commits into from

Conversation

kukovecz
Copy link
Contributor

Fixes #101

- Make changes in cli.py, move the core processing call to a function
called `unblob` and move the global exception handling logic there.
Now this function can be imported and used as a library as well as be
used from the Click-cli unchanged.
- Add instructions to README.md how to use it
When unblob is used as a library, the structlog may already be
configured as the end-user likes. In this case:
    1) We don't need to configure it again with our CLI config.
    2) We still need to apply the "pretty_print_types" processor to the
processor chain, so our types will be printed nicely.
We add this to the begining of the processor chain, because
    - It is lightweight
    - At the end of the processor chain must be some render, which will
convert the whole event_dict to str, and usually before the renderer,
there are various amount of error / exception formatters.
@kukovecz kukovecz force-pushed the 101-make-usable-as-library branch from f3cb0fe to 284bd73 Compare December 14, 2021 11:06
@kissgyorgy
Copy link
Contributor

GitHub folded the relevant comment:
#98 (comment)

                try:
                    chunk = handler.calculate_chunk(limited_reader, real_offset)
                except Exception as exc:
                    exit_code_var.set(1)

@vlaci wrote:

So this function should only be called from a CLI? It is very hard to use it from a library by masking errors. A possible way forward is to encapsulate errors into the chunks list (with a no-op or exception raising handler perhaps?)

@kissgyorgy kissgyorgy closed this Dec 14, 2021
@kukovecz kukovecz deleted the 101-make-usable-as-library branch December 17, 2021 17:15
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.

Make unblob usable as a library
2 participants