Skip to content

Commit

Permalink
feat: better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
altor committed Sep 28, 2021
1 parent d09fb2a commit fb7856d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
25 changes: 19 additions & 6 deletions powerapi/cli/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ def generate(self, config: Dict) -> Dict[str, Tuple[Type[Actor], StartMessage]]:
Generate an actor class and actor start message from config dict
"""
if self.component_group_name not in config:
print('CLI error : no ' + self.component_group_name + ' specified', file=sys.stderr)
print('CONFIG error : no ' + self.component_group_name + ' specified', file=sys.stderr)
sys.exit()

actors = {}

for component_name, component_config in config[self.component_group_name].items():
component_type = component_config['type']
try:
component_type = component_config['type']
actors[component_name] = self._gen_actor(component_type, component_config, config, component_name)
except KeyError as exn:
msg = 'CLI error : argument ' + exn.args[0]
msg += ' needed with --output ' + component_type
msg = 'CONFIG error : argument ' + exn.args[0]
msg += ' needed with output ' + component_type
print(msg, file=sys.stderr)
sys.exit()

Expand Down Expand Up @@ -362,10 +362,23 @@ def add_db_factory(self, db_name, db_factory):
self.model_factory[db_name] = db_factory

def _generate_db(self, db_name, db_config, _):
return self.db_factory[db_name](db_config)
if db_name not in self.db_factory:
msg = 'CONFIG error : database type ' + db_name + 'unknow'
print(msg, file=sys.stderr)
sys.exit()
else:
return self.db_factory[db_name](db_config)

def _generate_model(self, model_name, db_config):
if model_name not in self.model_factory:
msg = 'CONFIG error : model type ' + model_name + 'unknow'
print(msg, file=sys.stderr)
sys.exit()
else:
return self.model_factory[db_config['model']]

def _gen_actor(self, db_name, db_config, main_config, actor_name):
model = self.model_factory[db_config['model']]
model = self._generate_model(db_config['model'], db_config)
db_config['model'] = model
db = self._generate_db(db_name, db_config, main_config)
start_message = self._start_message_factory(actor_name, db, model, main_config['stream'], main_config['verbose'])
Expand Down
6 changes: 5 additions & 1 deletion powerapi/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def _extract_timestamp(ts):
try:
return datetime.strptime(ts, "%Y-%m-%dT%H:%M:%S.%f")
except ValueError:
return datetime.fromtimestamp(int(ts) / 1000)
try:
return datetime.fromtimestamp(int(ts) / 1000)
except ValueError:
ValueError('timestamp string have to be formated with the following format "%Y-%m-%dT%H:%M:%S.%f"')

if isinstance(ts, datetime):
return ts

Expand Down

0 comments on commit fb7856d

Please sign in to comment.