From 866645679a45cf2ec3fbf3b691e23782e48aaa0f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 19 Aug 2013 13:34:29 +0200 Subject: [PATCH] throw a better exception when environment variables are missing Signed-off-by: Nico Schottelius --- cdist/emulator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index af4c620e..22c819cd 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -28,7 +28,14 @@ import sys import cdist from cdist import core -class MissingEnvironmentVariable(cdist.Error): +class MissingRequiredEnvironmentVariableError(cdist.Error): + def __init__(self, name): + self.name = name + self.message = "Emulator requires the environment variable %s to be setup" % self.name + + def __str__(self): + return self.message + class Emulator(object): def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ): @@ -46,7 +53,8 @@ class Emulator(object): self.object_source = self.env['__cdist_manifest'] self.type_base_path = self.env['__cdist_type_base_path'] - except KeyError: + except KeyError as e: + raise MissingRequiredEnvironmentVariableError(e.args[0]) self.object_base_path = os.path.join(self.global_path, "object")