Skip to content

Commit

Permalink
python: Log error instead of "crash" upon failure to find environment
Browse files Browse the repository at this point in the history
Log an error, rather than crash with an exception, if we cannot find
any environment variables via `printenv`.  The intent here is to be
more resilient to bizarre platforms or those that are specifically
configured to not be so generous to us.

Fixes #37.
  • Loading branch information
jynik committed Dec 1, 2020
1 parent 75ee845 commit 91be987
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/depthcharge/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ def environment(self, cached=True) -> dict:
Note that all values in the returned dictionary are strings. The caller is responsible for
performing any necessary type conversions.
Upon failure, an error will be logged and an empty dictionary will be returned.
"""

if self._env is not None and cached:
Expand All @@ -664,7 +666,12 @@ def environment(self, cached=True) -> dict:
self.console.interrupt()
env_text = self.send_command('printenv')

self._env = uboot.env.parse(env_text)
try:
self._env = uboot.env.parse(env_text)
except ValueError as e:
log.error('Failed to parse environment: ' + str(e))
self._env = {}

return self._env

def env_var(self, name: str, expand=True, cached=True, convert_int=True, **kwargs):
Expand Down

0 comments on commit 91be987

Please sign in to comment.