Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallel: handle exceptions more modern-like #1265

Merged
merged 2 commits into from Mar 26, 2020

Conversation

@grahamc
Copy link
Member

grahamc commented Mar 26, 2020

In cases where the Exception type (like CommandFailed,) we would fail to recreate it later. With python3, we don't have to do this anymore, and can just hold on to the original exception.

@grahamc

This comment has been minimized.

Copy link
Member Author

grahamc commented Mar 26, 2020

The ratchet can't really be fixed in this case, as I don't think we can add any more types right now.

grahamc added 2 commits Mar 26, 2020
@grahamc grahamc force-pushed the grahamc:py3-fixup-exceptions branch from a1e9ee9 to 3ed0efa Mar 26, 2020
@grahamc

This comment has been minimized.

Copy link
Member Author

grahamc commented Mar 26, 2020

I added a test, too, and validated it failed in the way it was failing before:

[nix-shell:~/projects/github.com/NixOS/nixops]$ ./coverage-tests.py tests.unit.test_parallel
E....
======================================================================
ERROR: test_complicated_exception (tests.unit.test_parallel.ParallelTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/grahamc/projects/github.com/NixOS/nixops/tests/unit/test_parallel.py", line 73, in test_complicated_exception
    lambda task: task.todo(),
  File "/nix/store/n8nviwmllwqv0fjsar8v8k8gjap1vhcw-python3-3.7.6/lib/python3.7/unittest/case.py", line 756, in assertRaises
    return context.handle('assertRaises', args, kwargs)
  File "/nix/store/n8nviwmllwqv0fjsar8v8k8gjap1vhcw-python3-3.7.6/lib/python3.7/unittest/case.py", line 178, in handle
    callable_obj(*args, **kwargs)
  File "/home/grahamc/projects/github.com/NixOS/nixops/nixops/parallel.py", line 117, in run_tasks
    raise excinfo[0](excinfo[1]).with_traceback(excinfo[2])
TypeError: __init__() missing 1 required positional argument: 'arg2'

Name                                Stmts   Miss  Cover
-------------------------------------------------------
nixops/__init__.py                      0      0   100%
nixops/ansi.py                         10      2    80%
nixops/backends/__init__.py           268    205    24%
nixops/backends/none.py                65     39    40%
nixops/deployment.py                  830    501    40%
nixops/diff.py                        115     92    20%
nixops/logger.py                      111     66    41%
nixops/nix_expr.py                    198     64    68%
nixops/parallel.py                     81      5    94%
nixops/plugins/__init__.py              8      0   100%
nixops/plugins/hookspecs.py             5      0   100%
nixops/resources/__init__.py          167     97    42%
nixops/resources/commandOutput.py      58     31    47%
nixops/resources/ssh_keypair.py        33     15    55%
nixops/ssh_util.py                    183    143    22%
nixops/state.py                        47     34    28%
nixops/statefile.py                   144     48    67%
nixops/util.py                        290    183    37%
-------------------------------------------------------
TOTAL                                2613   1525    42%
----------------------------------------------------------------------
Ran 5 tests in 0.026s

FAILED (errors=1)

[nix-shell:~/projects/github.com/NixOS/nixops]$ git rebase --continue
Successfully rebased and updated refs/heads/py3-fixup-exceptions.

[nix-shell:~/projects/github.com/NixOS/nixops]$ ./coverage-tests.py tests.unit.test_parallel
.....
Name                                Stmts   Miss  Cover
-------------------------------------------------------
nixops/__init__.py                      0      0   100%
nixops/ansi.py                         10      2    80%
nixops/backends/__init__.py           268    205    24%
nixops/backends/none.py                65     39    40%
nixops/deployment.py                  830    501    40%
nixops/diff.py                        115     92    20%
nixops/logger.py                      111     66    41%
nixops/nix_expr.py                    198     64    68%
nixops/parallel.py                     78      7    91%
nixops/plugins/__init__.py              8      0   100%
nixops/plugins/hookspecs.py             5      0   100%
nixops/resources/__init__.py          167     97    42%
nixops/resources/commandOutput.py      58     31    47%
nixops/resources/ssh_keypair.py        33     15    55%
nixops/ssh_util.py                    183    143    22%
nixops/state.py                        47     34    28%
nixops/statefile.py                   144     48    67%
nixops/util.py                        290    183    37%
-------------------------------------------------------
TOTAL                                2610   1527    41%
----------------------------------------------------------------------
Ran 5 tests in 0.034s

OK
@grahamc grahamc force-pushed the grahamc:py3-fixup-exceptions branch 2 times, most recently from 503bdbc to 3ed0efa Mar 26, 2020
@domenkozar domenkozar merged commit 200888a into NixOS:master Mar 26, 2020
10 of 12 checks passed
10 of 12 checks passed
parsing
Details
parsing
Details
build
Details
build
Details
black
Details
black
Details
mypy
Details
mypy
Details
mypy-ratchet mypy-ratchet
Details
mypy-ratchet mypy-ratchet
Details
coverage
Details
coverage
Details
@grahamc grahamc deleted the grahamc:py3-fixup-exceptions branch Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.