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

Improved error handling and readability of extractor #826

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

Niraj-Kamdar
Copy link
Contributor

No description provided.

Comment on lines +50 to +55
@staticmethod
async def extract_file_tar(filename, extraction_path):
""" Extract tar files """
try:
with ErrorHandler(mode=ErrorMode.Ignore) as e:
await aio_unpack_archive(filename, extraction_path)
return 0
except Exception:
return 1
return e.exit_code
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is static method because we don't need class attribute here. We are just ignoring error

Comment on lines +61 to +64
with ErrorHandler(mode=self.error_mode, logger=self.logger):
raise Exception(
"'rpm2cpio' and 'cpio' are required to extract rpm files"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we are raising error so, we want to log that.

Comment on lines -214 to +210
class Extractor(BaseExtractor):
def Extractor(*args, **kwargs):
"""Provides a context which extraction is done in"""

def __call__(self, *args, **kwargs):
return TempDirExtractorContext(*args, **kwargs)
return TempDirExtractorContext(*args, **kwargs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create function instead of callable class for better readability. Ex:
Extractor()(error_mode=mode) will now become Extractor(error_mode=mode)

@Niraj-Kamdar Niraj-Kamdar changed the title [Part 2] Improved error handling in extractor [Part 2] Improved error handling and readability of extractor Jul 18, 2020
@Niraj-Kamdar Niraj-Kamdar changed the title [Part 2] Improved error handling and readability of extractor Improved error handling and readability of extractor Jul 18, 2020
@codecov-commenter
Copy link

Codecov Report

Merging #826 into master will increase coverage by 5.42%.
The diff coverage is 73.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #826      +/-   ##
==========================================
+ Coverage   83.16%   88.58%   +5.42%     
==========================================
  Files         150      150              
  Lines        2542     2541       -1     
  Branches      279      278       -1     
==========================================
+ Hits         2114     2251     +137     
+ Misses        359      227     -132     
+ Partials       69       63       -6     
Flag Coverage Δ
#longtests 88.58% <73.91%> (+5.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cve_bin_tool/extractor.py 60.62% <66.66%> (+2.61%) ⬆️
cve_bin_tool/cli.py 84.48% <100.00%> (+5.17%) ⬆️
cve_bin_tool/version_scanner.py 86.08% <100.00%> (+2.15%) ⬆️
test/test_cli.py 100.00% <100.00%> (+17.07%) ⬆️
test/test_extractor.py 97.80% <100.00%> (ø)
cve_bin_tool/error_handler.py 85.71% <0.00%> (+4.08%) ⬆️
test/test_scanner.py 90.58% <0.00%> (+10.58%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f35ef84...1170515. Read the comment docs.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I'll leave it to @pdxjohnny to approve since he wrote the original code and might have more precise feedback.

@terriko terriko added the awaiting maintainer Need a maintainer to respond / help out label Jul 20, 2020
@terriko
Copy link
Contributor

terriko commented Jul 23, 2020

K, it's been 3 days, I'm going to assume @pdxjohnny doesn't have time to review this. Looks good enough to me so let's get it merged!

@terriko terriko merged commit 5c80438 into intel:master Jul 23, 2020
@Niraj-Kamdar Niraj-Kamdar deleted the error branch July 24, 2020 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting maintainer Need a maintainer to respond / help out
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants