fix: print errors to stderr

This commit is contained in:
2026-02-21 20:43:17 +03:00
parent fad35ec04b
commit 8a4deb39f5

View File

@@ -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}"')
t[k] = p # substituting path (e.g. "~/somedir" -> "/home/user/somedir")
if errors:
print(f'{err_count} errors found in the config "{conf_file_path}":')
print('\n'.join(errors))
print(f'{err_count} errors found in the config "{conf_file_path}":', file=sys.stderr)
print('\n'.join(errors), file=sys.stderr)
raise ValueError('invalid config')
def get_contexts_list(self) -> list[str]:
@@ -274,12 +274,12 @@ class Runner(object):
try: # just in case
args = p.parse_args()
except Exception as e:
print("error parsing command-line arguments:", e)
print("error parsing command-line arguments:", e, file=sys.stderr)
return 1
try:
config = ContextManagerConfig(args.config, args.nop)
except Exception as e:
print("error loading config:", e)
print("error loading config:", e, file=sys.stderr)
return 2
try:
ctxmgr = ContextManager(config)
@@ -288,7 +288,7 @@ class Runner(object):
elif args.command == COMMAND_APPLY:
ctxmgr.apply_context(args.__dict__[COMMAND_CTX_NAME]) # guaranteed to be present by argparse
except Exception as e:
print(f'error executing command:', e)
print(f'error executing command:', e, file=sys.stderr)
return 3
return 0