Skip to content

Commit

Permalink
improve exception handling, don't bother trying to parse an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed May 6, 2021
1 parent b7603a5 commit 9371b43
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions xpra/server/server_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ def env_from_sourcing(file_to_source_path, include_unexported_variables=False):
proc = subprocess.Popen(['/bin/bash', '-c', '%s && %s' % (source, dump)], stdout=subprocess.PIPE)
out = proc.communicate()[0]
if proc.returncode!=0:
log.warn("Error %i running source script for '%s'", proc.returncode, file_to_source_path)
except OSError:
log.error("Error %i running source script '%s'", proc.returncode, file_to_source_path)
except OSError as e:
log("env_from_sourcing%s", (file_to_source_path, include_unexported_variables), exc_info=True)
log(" stdout=%r (%s)", out, type(out))
log.error("Error running source script '%s'", proc.returncode, file_to_source_path)
log.error(" %s", e)
return {}
log("json(%s)=%r", file_to_source_path, out)
if not out:
return {}
try:
return json.loads(out)
except json.decoder.JSONDecodeError:
return json.loads(out.decode())
except (json.decoder.JSONDecodeError, UnicodeDecodeError):
log.error("Error decoding json output from sourcing script '%s'", file_to_source_path, exc_info=True)
return {}

Expand Down

0 comments on commit 9371b43

Please sign in to comment.