Giter VIP home page Giter VIP logo

cumulus-message-adapter-python's Issues

invalid requirements.txt format

When installing this package using Poetry I received the following error message

Invalid constraint (cumulus-message-adapter>=2.0.0<2.1.0) found in cumulus-message-adapter-python-2.0.1 dependencies, skipping

After reviewing the source code I noticed that the entry in the requirements.txt file is malformed. Per PEP 440 version clauses should be separated by a comma.

Recommended fix is to update requirements.txt file to
cumulus-message-adapter>=2.0.0, <2.1.0

Conda Package

It's great that cumulus-message-adapter-python is available on pypi. I'm wondering if you would consider making it available on conda-forge too? I'm happy to do the initial legwork, but it would be good to keep the maintainers of this repository as the maintainers on the conda recipe. Thoughts?

The way `CumulusLogger.createMessage` calls `str.format` prevents log/exception messages from containing curly braces if no args/kwargs are given

Sometimes we want our lambda to log messages that include a JSON string, but provide a little context, such as 'Post to CMR response: <JSON here>'. Unfortunately, that causes an error if passed as a string to logger.debug (and the other functions) or is included in the error message, due to this line:

https://github.com/nasa/cumulus-message-adapter-python/blob/v1.2.1/cumulus_logger.py#L213

That is, this code leads to a KeyError: '"easter_bunny"':

from cumulus_logger import CumulusLogger
logger = CumulusLogger()
response_txt = '{"easter_bunny": "fake sample response"}'
logger.debug(f'POST to CMR response: {response_txt}')

And this code leads to an IndexError: Replacement index 0 out of range for positional args tuple:

logger.debug('POST to CMR response: {}')

When we first encountered this and I tracked down the .format() call on the LOC I linked above, I realized I could work around this issue with this code change:

# # broken version from above
# response_txt = '{"easter_bunny": "fake sample response"}'
# logger.debug(f'POST to CMR response: {response_txt}')

# workaround, send the JSON string to str.format's **kwargs
logger.debug('POST to CMR response: {response}', response=response_text)

However, this did not fully eliminate the KeyErrors; in the case where the CMR request failed, we raise an Exception so that the lambda fails appropriately:

if not response.ok:
    raise RuntimeError('Post to CMR Failed:', response.text)

And when cumulus-message-adapter-python tries to log the exception object at...

https://github.com/nasa/cumulus-message-adapter-python/blob/v1.2.1/run_cumulus_task.py#L68

...the exception gets converted to a string, .format() is called, and once again any curly braces in the message lead to a KeyError or IndexError.

I want to be able to have curly brace characters in my strings passed to the logger without an error being raised. #39 accomplishes this while maintaining the .format() functionality by skipping the .format() call if no args or kwargs are given.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.