fix: print errors to stderr
This commit is contained in:
10
userctx.py
10
userctx.py
@@ -208,8 +208,8 @@ class ContextManagerConfig(object):
|
|||||||
errors.append(f'{err_count}. {errstr} path "{v}" in key "{k}" must be either absolute or relative to home: "~/{v}"')
|
errors.append(f'{err_count}. {errstr} path "{v}" in key "{k}" must be either absolute or relative to home: "~/{v}"')
|
||||||
t[k] = p # substituting path (e.g. "~/somedir" -> "/home/user/somedir")
|
t[k] = p # substituting path (e.g. "~/somedir" -> "/home/user/somedir")
|
||||||
if errors:
|
if errors:
|
||||||
print(f'{err_count} errors found in the config "{conf_file_path}":')
|
print(f'{err_count} errors found in the config "{conf_file_path}":', file=sys.stderr)
|
||||||
print('\n'.join(errors))
|
print('\n'.join(errors), file=sys.stderr)
|
||||||
raise ValueError('invalid config')
|
raise ValueError('invalid config')
|
||||||
|
|
||||||
def get_contexts_list(self) -> list[str]:
|
def get_contexts_list(self) -> list[str]:
|
||||||
@@ -274,12 +274,12 @@ class Runner(object):
|
|||||||
try: # just in case
|
try: # just in case
|
||||||
args = p.parse_args()
|
args = p.parse_args()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error parsing command-line arguments:", e)
|
print("error parsing command-line arguments:", e, file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
try:
|
try:
|
||||||
config = ContextManagerConfig(args.config, args.nop)
|
config = ContextManagerConfig(args.config, args.nop)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error loading config:", e)
|
print("error loading config:", e, file=sys.stderr)
|
||||||
return 2
|
return 2
|
||||||
try:
|
try:
|
||||||
ctxmgr = ContextManager(config)
|
ctxmgr = ContextManager(config)
|
||||||
@@ -288,7 +288,7 @@ class Runner(object):
|
|||||||
elif args.command == COMMAND_APPLY:
|
elif args.command == COMMAND_APPLY:
|
||||||
ctxmgr.apply_context(args.__dict__[COMMAND_CTX_NAME]) # guaranteed to be present by argparse
|
ctxmgr.apply_context(args.__dict__[COMMAND_CTX_NAME]) # guaranteed to be present by argparse
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error executing command:', e)
|
print(f'error executing command:', e, file=sys.stderr)
|
||||||
return 3
|
return 3
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user