Skip to content

Use sys.exit and write to stderr in the error handler - #504

Open
jacalata wants to merge 1 commit into
developmentfrom
jac/fix-connection-error-exit
Open

jacalata wants to merge 1 commit into
developmentfrom
jac/fix-connection-error-exit

Conversation

@jacalata

Copy link
Copy Markdown
Contributor

When the server cannot be reached, Errors.check_common_error_codes_and_explain prints the connection error and calls exit(1). exit is a builtin added by the site module, and PyInstaller builds do not have it. In the packaged executable the call raises NameError, which exit_with_error catches and reports as a garbled line before exiting:

<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'> Error during log call from exception - <class 'NameError'> None

Running from source does not show this. The exit status is 1 either way.

  • The ConnectionError branch now calls sys.exit(1).
  • The two fallback prints in exit_with_error used print(sys.stderr, ...), which prints the stream object to stdout. They now use file=sys.stderr.
  • New tests in tests/commands/test_errors.py cover both. They fail without the change.

I found this by running the executable built from development against an unreachable server.

🤖 Generated with Claude Code

The ConnectionError branch of check_common_error_codes_and_explain called the
site builtin exit(1), which does not exist in a PyInstaller build, so the
packaged executable raised NameError and printed a stray line before exiting.
The fallback prints also passed sys.stderr as the first argument to print
instead of using file=sys.stderr.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 07:55
@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
tabcmd
   __main__.py121212 0%
   _version.py111111 0%
   tabcmd.py151515 0%
   version.py1066 40%
tabcmd/commands
   commands.py101010 0%
   constants.py771313 83%
   server.py1351818 87%
tabcmd/commands/auth
   session.py4164646 89%
tabcmd/commands/datasources_and_workbooks
   datasources_and_workbooks_command.py1701818 89%
   datasources_workbooks_views_url_parser.py14255 96%
   delete_command.py702323 67%
   export_command.py1262121 83%
   get_url_command.py1274747 63%
   publish_command.py1341616 88%
   runschedule_command.py2177 67%
tabcmd/commands/extracts
   create_extracts_command.py4288 81%
   decrypt_extracts_command.py2722 93%
   delete_extracts_command.py3766 84%
   encrypt_extracts_command.py2722 93%
   extracts.py2022 90%
   reencrypt_extracts_command.py2722 93%
   refresh_extracts_command.py481010 79%
tabcmd/commands/group
   create_group_command.py2955 83%
   delete_group_command.py2722 93%
tabcmd/commands/project
   create_project_command.py4688 83%
   delete_project_command.py3544 89%
   publish_samples_command.py3044 87%
tabcmd/commands/site
   create_site_command.py3455 85%
   delete_site_command.py2722 93%
   edit_site_command.py661818 73%
   list_command.py771212 84%
   list_sites_command.py2922 93%
tabcmd/commands/user
   add_users_command.py2955 83%
   create_site_users.py1151414 88%
   create_users_command.py5999 85%
   delete_site_users_command.py4355 88%
   user_data.py2303030 87%
tabcmd/execution
   _version.py222 0%
   global_options.py15544 97%
   localize.py671111 84%
   logger_config.py7266 92%
   tabcmd_controller.py4077 82%
TOTAL307045585% 

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants