From 8a4deb39f5e14d300571b28721fcc5d42a54e90e Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Sat, 21 Feb 2026 20:43:17 +0300 Subject: [PATCH] fix: print errors to stderr --- userctx.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/userctx.py b/userctx.py index 0b3d38a..1685407 100755 --- a/userctx.py +++ b/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}"') 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