forked from LBRYCommunity/lbry-sdk
show where the log file is, and log failure to open file better
This commit is contained in:
parent
49869d071a
commit
ec1ba02cca
2 changed files with 23 additions and 8 deletions
|
@ -12,6 +12,11 @@ from lbrynet.lbryfile.client.LBRYFileMetadataHandler import LBRYFileMetadataHand
|
|||
import os
|
||||
from twisted.internet import defer, threads, reactor
|
||||
from twisted.python.procutils import which
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LBRYFileDownloader(CryptStreamDownloader):
|
||||
|
@ -178,7 +183,13 @@ class LBRYFileSaver(LBRYFileDownloader):
|
|||
file_name + "_" + str(ext_num))):
|
||||
ext_num += 1
|
||||
file_name = file_name + "_" + str(ext_num)
|
||||
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb')
|
||||
try:
|
||||
self.file_handle = open(os.path.join(self.download_directory, file_name), 'wb')
|
||||
except IOError:
|
||||
log.error(traceback.format_exc())
|
||||
raise ValueError("Failed to open %s. Make sure you have permission to save files to that"
|
||||
" location." % str(os.path.join(self.download_directory,
|
||||
file_name)))
|
||||
return threads.deferToThread(open_file)
|
||||
|
||||
def _close_output(self):
|
||||
|
|
|
@ -54,6 +54,14 @@ class InvalidValueError(Exception):
|
|||
# prompt_description = None
|
||||
|
||||
|
||||
def get_log_file():
|
||||
log_file = "console.log"
|
||||
logging_handlers = logging.getLogger().handlers
|
||||
if len(logging_handlers):
|
||||
log_file = logging_handlers[0].baseFilename
|
||||
return log_file
|
||||
|
||||
|
||||
class RoundedTime(object):
|
||||
SECOND = 0
|
||||
MINUTE = 1
|
||||
|
@ -611,9 +619,7 @@ class AddStream(CommandHandler):
|
|||
def _handle_load_failed(self, err):
|
||||
self.loading_failed = True
|
||||
log.error("An exception occurred attempting to load the stream descriptor: %s", err.getTraceback())
|
||||
log_file = "console.log"
|
||||
if len(log.handlers):
|
||||
log_file = log.handlers[0].baseFilename
|
||||
log_file = get_log_file()
|
||||
self.console.sendLine("An unexpected error occurred attempting to load the stream's metadata.\n"
|
||||
"See %s for further details.\n\n" % log_file)
|
||||
self.finished_deferred.callback(None)
|
||||
|
@ -771,10 +777,8 @@ class AddStream(CommandHandler):
|
|||
d.addErrback(self._log_recent_blockchain_time_error_download)
|
||||
else:
|
||||
log.error("An unexpected error has caused the download to stop: %s" % err.getTraceback())
|
||||
log_file = "console.log"
|
||||
if len(log.handlers):
|
||||
log_file = log.handlers[0].baseFilename
|
||||
self.console.sendLine("An unexpected error has caused the download to stop. See %s for details." % log_file)
|
||||
log_file = get_log_file()
|
||||
self.console.sendLine("An unexpected error has caused the download to stop:\n%s\n\nSee %s for further details." % (err.getErrorMessage(), log_file))
|
||||
|
||||
def _make_downloader(self):
|
||||
return self.factory.make_downloader(self.metadata, self.options_chosen,
|
||||
|
|
Loading…
Reference in a new issue