-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Errors and warnings are printed to stderr. #919
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,15 +274,15 @@ def run(self): | |
|
||
def _process_print_task(self, print_task): | ||
print_str = print_task.message | ||
print_to_stderr = False | ||
if print_task.error: | ||
self.num_errors_seen += 1 | ||
warning = False | ||
if print_task.warning: | ||
if print_task.warning: | ||
warning = True | ||
self.num_warnings_seen += 1 | ||
print_to_stderr = True | ||
|
||
final_str = '' | ||
if warning: | ||
if print_task.warning: | ||
self.num_warnings_seen += 1 | ||
print_to_stderr = True | ||
final_str += print_str.ljust(self._progress_length, ' ') | ||
final_str += '\n' | ||
elif print_task.total_parts: | ||
|
@@ -309,21 +309,30 @@ def _process_print_task(self, print_task): | |
self._num_parts += 1 | ||
self._file_count += 1 | ||
|
||
# If the message is an error or warning, print it to standard error. | ||
if print_to_stderr and not self._quiet: | ||
uni_print(final_str, sys.stderr) | ||
final_str = '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want to not return after this line? Do we still want to print the progress on an error? For example:
Looks a bit off to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not want to return. The progress bar should always be the last thing printed for each print task, unless it is the last file. The example you gave is legitimate since the If I was to put a return at the end of the that code block, there can be scenarios when the user is without the progress bar for a long period of time. For example, if you had a bunch, like thousands of failed uploads, the progress bar would never show up because we never print it, and therefore the user would have no idea when the command is reaching an end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the example I gave above, it is the last file we try to sync. Specifically I have three files in my directory, 1 that is unreadable. Running the sync command I get:
The last line seems out of place to me and I don't think it should be there. I'm not saying we shouldn't have progress messages, but it seems like there are cases where we print a progress message that shouldn't be printed, such as in my example above. Given this behavior existed prior to this change (I only noticed because you're modifying this area of the code and it stood out), I would be ok with addressing this as a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I just tested this and I cannot repo this output:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on the order of the files. For example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. It is an easy fix. We just need to put an additional check in there that if I can make another pull request later to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or I meant |
||
|
||
is_done = self._total_files == self._file_count | ||
if not is_done: | ||
prog_str = "Completed %s " % self._num_parts | ||
num_files = self._total_files | ||
if self._total_files != '...': | ||
prog_str += "of %s " % self._total_parts | ||
num_files = self._total_files - self._file_count | ||
prog_str += "part(s) with %s file(s) remaining" % \ | ||
num_files | ||
length_prog = len(prog_str) | ||
prog_str += '\r' | ||
prog_str = prog_str.ljust(self._progress_length, ' ') | ||
self._progress_length = length_prog | ||
final_str += prog_str | ||
final_str += self._make_progress_bar() | ||
if not self._quiet: | ||
uni_print(final_str) | ||
self._needs_newline = not final_str.endswith('\n') | ||
sys.stdout.flush() | ||
|
||
def _make_progress_bar(self): | ||
"""Creates the progress bar string to print out.""" | ||
|
||
prog_str = "Completed %s " % self._num_parts | ||
num_files = self._total_files | ||
if self._total_files != '...': | ||
prog_str += "of %s " % self._total_parts | ||
num_files = self._total_files - self._file_count | ||
prog_str += "part(s) with %s file(s) remaining" % \ | ||
num_files | ||
length_prog = len(prog_str) | ||
prog_str += '\r' | ||
prog_str = prog_str.ljust(self._progress_length, ' ') | ||
self._progress_length = length_prog | ||
return prog_str |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ def setUp(self): | |
self.session = FakeSession() | ||
self.service = self.session.get_service('s3') | ||
self.endpoint = self.service.get_endpoint('us-east-1') | ||
params = {'region': 'us-east-1', 'acl': ['private']} | ||
params = {'region': 'us-east-1', 'acl': ['private'], 'quiet': True} | ||
self.s3_handler = S3Handler(self.session, params) | ||
self.s3_handler_multi = S3Handler(self.session, multi_threshold=10, | ||
chunksize=2, | ||
|
@@ -275,7 +275,7 @@ def setUp(self): | |
self.session = FakeSession(True, True) | ||
self.service = self.session.get_service('s3') | ||
self.endpoint = self.service.get_endpoint('us-east-1') | ||
params = {'region': 'us-east-1'} | ||
params = {'region': 'us-east-1', 'quiet': True} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the tests involve testing failing multipart tasks. However, the failures get printed to stderr now, and those messages were getting mixed with dots when running nose, which was annoying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that makes sense. It was just that from a reviewer's perspective this change seemed out of place without any comment or explanation in the PR so it wasn't clear if this was a mistake or intentional, and if so what its purpose was. Not opposed to leaving this. |
||
self.s3_handler_multi = S3Handler(self.session, params, | ||
multi_threshold=10, chunksize=2) | ||
self.bucket = create_bucket(self.session) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the newly added lines here, this method is now 62 lines long. Let's split this up to make it easier to manage.