Commit 9b6925e
authored
Always exit unsuccessfully with
`exit` is undefined when the `site` module isn't loaded (i.e. when
Python is executed with the `-S` option), and `exit` isn't explicitly
defined as a function or imported from elsewhere in `main.py`, so
reaching any code path that attempts to execute `exit(1)` in this
environment results in a `NameError` being raised:
```
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "[...]/__main__.py", line 415, in <module>
File "[...]/__main__.py", line 399, in run
File "[...]/__main__.py", line 389, in main
File "/usr/lib/python3.10/runpy.py", line 220, in run_module
mod_name, mod_spec, code = _get_module_details(mod_name)
File "/usr/lib/python3.10/runpy.py", line 157, in _get_module_details
code = loader.get_code(mod_name)
File "[...]/__main__.py", line 264, in get_code
File "[...]/__main__.py", line 204, in load_module
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "third_party/python3/__pgcli_main__.py", line 3, in <module>
File "[...]/click/core.py", line 1157, in __call__
File "[...]/click/core.py", line 1078, in main
File "[...]/click/core.py", line 1434, in invoke
File "[...]/click/core.py", line 783, in invoke
File "[...]/pgcli/main.py", line 1617, in cli
File "[...]/pgcli/main.py", line 766, in connect
NameError: name 'exit' is not defined. Did you mean: 'atexit'?
```
When exiting unsuccessfully, do so with `sys.exit(1)` - this is already
used in several other places in `main.py`, and is always used (with exit
code 0) when exiting successfully.sys.exit (#1481)1 parent 0fa81ef commit 9b6925e
3 files changed
+12
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
613 | | - | |
| 613 | + | |
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
713 | | - | |
| 713 | + | |
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
| |||
763 | 763 | | |
764 | 764 | | |
765 | 765 | | |
766 | | - | |
| 766 | + | |
767 | 767 | | |
768 | 768 | | |
769 | 769 | | |
| |||
1551 | 1551 | | |
1552 | 1552 | | |
1553 | 1553 | | |
1554 | | - | |
| 1554 | + | |
1555 | 1555 | | |
1556 | 1556 | | |
1557 | 1557 | | |
| |||
1560 | 1560 | | |
1561 | 1561 | | |
1562 | 1562 | | |
1563 | | - | |
| 1563 | + | |
1564 | 1564 | | |
1565 | 1565 | | |
1566 | 1566 | | |
| |||
1604 | 1604 | | |
1605 | 1605 | | |
1606 | 1606 | | |
1607 | | - | |
| 1607 | + | |
1608 | 1608 | | |
1609 | 1609 | | |
1610 | 1610 | | |
1611 | 1611 | | |
1612 | 1612 | | |
1613 | 1613 | | |
1614 | 1614 | | |
1615 | | - | |
| 1615 | + | |
1616 | 1616 | | |
1617 | 1617 | | |
1618 | 1618 | | |
| |||
0 commit comments