Skip to content

Commit

Permalink
Modify ExceptionHandler.write_out to properly show errors (conda#11746
Browse files Browse the repository at this point in the history
)

`ExceptionHandler.write_out` writes out to the `conda.stderr` logger. If an exception occurs during `argparse` startup or during argument parsing then the logger is uninitialized and the exception handler ends up writing into the void. Avoid this by (re-)initializing the loggers before writing to the logger.

Co-authored-by: Ken Odegard <[email protected]>
  • Loading branch information
beeankha and kenodegard authored Aug 24, 2022
1 parent ccc6fbc commit d70d318
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
26 changes: 13 additions & 13 deletions conda/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,14 +1133,10 @@ def __call__(self, func, *args, **kwargs):

def write_out(self, *content):
from .base.context import context
from .cli.main import init_loggers

content_str = "\n".join(content)
if True:
logger = getLogger("conda.%s" % ("stdout" if context.json else "stderr"))
logger.info(content_str)
else:
stream = sys.stdout if context.json else sys.stderr
stream.write(content_str)
init_loggers(context)
getLogger("conda.stderr").info("\n".join(content))

@property
def http_timeout(self):
Expand Down Expand Up @@ -1340,13 +1336,17 @@ def _upload(self, error_report) -> None:
self._post_upload(do_upload)

def _ask_upload(self):
self.write_out(
"If submitted, this report will be used by core maintainers to improve",
"future releases of conda.",
"Would you like conda to send this report to the core maintainers?",
)
try:
do_upload = timeout(40, partial(input, "[y/N]: "))
do_upload = timeout(
40,
partial(
input,
"If submitted, this report will be used by core maintainers to improve\n"
"future releases of conda.\n"
"Would you like conda to send this report to the core maintainers? "
"[y/N]: ",
),
)
return do_upload and boolify(do_upload)
except Exception as e:
log.debug("%r", e)
Expand Down
19 changes: 19 additions & 0 deletions news/11746-modify-write-out
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Ensure that exceptions that are raised show up properly instead of resulting in a random [y/N] prompt (#11746)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>

0 comments on commit d70d318

Please sign in to comment.