Handle decode error

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2024-02-16 00:46:00 +02:00
parent e92954e8ac
commit d0930ee050
3 changed files with 43 additions and 18 deletions

View File

@ -446,7 +446,10 @@ class TaskConfig:
return False
code = self.suproc.returncode
if code != 0:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract archive splits!. Path: {f_path}"
)
@ -499,7 +502,10 @@ class TaskConfig:
self.cancelled = True
return up_path
elif code != -9:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract archive! Uploading anyway. Path: {dl_path}"
)
@ -583,7 +589,10 @@ class TaskConfig:
await clean_target(self.newDir)
if not delete:
self.newDir = ""
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Unable to zip this path: {dl_path}")
return dl_path
else:

View File

@ -177,8 +177,14 @@ async def cmd_exec(cmd, shell=False):
else:
proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = await proc.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
try:
stdout = stdout.decode().strip()
except:
stdout = "Unable to decode the response!"
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
return stdout, stderr, proc.returncode

View File

@ -49,11 +49,14 @@ async def convert_video(listener, video_file, ext, retry=False):
listener.cancelled = True
return False
else:
stderr = stderr.decode().strip()
LOGGER.error(
f"{f'{stderr}. ' if retry else ''}Something went wrong while converting video, mostly file need specific codec. {'' if retry else 'Retrying with specific codec'}. Path: {video_file}"
)
if not retry:
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}Something went wrong while converting video, mostly file need specific codec. Path: {video_file}"
)
if await aiopath.exists(output):
await remove(output)
return await convert_video(listener, video_file, ext, True)
@ -84,7 +87,10 @@ async def convert_audio(listener, audio_file, ext):
listener.cancelled = True
return False
else:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Something went wrong while converting audio, mostly file need specific codec. Path: {audio_file}"
)
@ -119,8 +125,6 @@ async def is_multi_streams(path):
path,
]
)
if res := result[1]:
LOGGER.warning(f"Get Video Streams: {res} - File: {path}")
except Exception as e:
LOGGER.error(f"Get Video Streams: {e}. Mostly File not found! - File: {path}")
return False
@ -154,8 +158,6 @@ async def get_media_info(path):
path,
]
)
if res := result[1]:
LOGGER.warning(f"Get Media Info: {res} - File: {path}")
except Exception as e:
LOGGER.error(f"Get Media Info: {e}. Mostly File not found! - File: {path}")
return 0, None, None
@ -199,7 +201,6 @@ async def get_document_type(path):
]
)
if res := result[1]:
LOGGER.warning(f"Get Document Type: {res} - File: {path}")
if mime_type.startswith("video"):
is_video = True
except Exception as e:
@ -399,7 +400,10 @@ async def split_file(
listener.cancelled = True
return False
elif code != 0:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
try:
await remove(out_path)
except:
@ -480,7 +484,10 @@ async def split_file(
listener.cancelled = True
return False
elif code != 0:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Split Document: {path}")
return True
@ -545,7 +552,10 @@ async def createSampleVideo(listener, video_file, sample_duration, part_duration
elif code == 0:
return output_file
else:
stderr = stderr.decode().strip()
try:
stderr = stderr.decode().strip()
except:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Something went wrong while creating sample video, mostly file is corrupted. Path: {video_file}"
)