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

CASMPET-6723 catch UnicodeDecodeError from os/run_command #54

Merged
merged 12 commits into from
Aug 10, 2023
Merged

Conversation

leliasen-hpe
Copy link
Contributor

Summary and Scope

UnicodeDecodeError was seen once when testing the bss-set-image function. It is unclear what caused this error. A catch statement was added so that if this is seen again, we can better debug it.

Additionally, as part of this PR the spacing is fixed in the text of raise statement. The extra whitespace is removed.

Prerequisites

  • I have included documentation in my PR (or it is not required).
  • I have added unit tests for my code.

Idempotency

Risks and Mitigations

@kburns-hpe
Copy link

Looks like your editor changed the indentions for multiple files without any other change. Guessing we'd want a standard set of editor configs so that this doesn't happen.

libcsm/sls/api.py Outdated Show resolved Hide resolved
response from sls. These fields are expected in the json response. \
The resonponse was {components_response.json()}') from error
response from sls. These fields are expected in the json response. \
The resonponse was {components_response.json()}') from error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response here too.

Also what happens if the response.json() call fails in the exception handler or throws its own exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for @leliasen-hpe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed this by using a try-except statement and catching a JSONDecodeError. I think this is the only exception thrown by .json(). Does that seem sufficient @mitchty @rustydb ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to ValueError. JSONDecodeError inherits from ValueError so this will correctly catch the error.

libcsm/os.py Outdated Show resolved Hide resolved
libcsm/tests/test_os.py Show resolved Hide resolved
libcsm/tests/test_os.py Show resolved Hide resolved
@rustydb rustydb requested a review from mitchty August 9, 2023 16:57
Make the `decode` an optional, and just return the string as bytes
unless the developer has passed an encoding.

It is false to assume an encoding, and auto-resolving the encoding is
unreliable.
@leliasen-hpe
Copy link
Contributor Author

Looks like your editor changed the indentions for multiple files without any other change. Guessing we'd want a standard set of editor configs so that this doesn't happen.

@kburns-hpe, I intentionally unindented all of those blocks, it wasn't an editor. All those indents were leaving large whitespaces in the print statements so I got rid of the indention.

@mitchty
Copy link
Contributor

mitchty commented Aug 10, 2023

Looks like your editor changed the indentions for multiple files without any other change. Guessing we'd want a standard set of editor configs so that this doesn't happen.

@kburns-hpe, I intentionally unindented all of those blocks, it wasn't an editor. All those indents were leaving large whitespaces in the print statements so I got rid of the indention.

Instead of moving the strings to the left just do like this so the format strings can be multiline:

      f"foo" \
      f"bar"

Etc...

libcsm/sls/api.py Outdated Show resolved Hide resolved
@rustydb rustydb merged commit 683a21a into main Aug 10, 2023
@rustydb rustydb deleted the CASMPET-6723 branch August 10, 2023 20:08
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.

4 participants