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

Re-raise Kubernetes exceptions as HttpError #33

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

TomAugspurger
Copy link
Collaborator

Here's the CLI output now:

kbatch job submit --name=TEST --image="alpine"
[14:22:15] ERROR    {'detail': '{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Job.batch \\"TEST-6c6wr\\" is invalid: [metadata.generateName: Invalid value: \\"TEST-\\": a DNS-1123 subdomain must consist of lower case         _core.py:226
                    alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\'), metadata.name:
                    Invalid value: \\"TEST-6c6wr\\": a DNS-1123 subdomain must consist of lower case alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')]","reason":"Invalid","details":{"name":"TEST-6c6wr","group":"batch","kind":"Job","causes":[{"reason":"FieldValueInvalid","message":"Invalid value: \\"TEST-\\": a
                    DNS-1123 subdomain must consist of lower case alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')","field":"metadata.generateName"},{"reason":"FieldValueInvalid","message":"Invalid value: \\"TEST-6c6wr\\": a DNS-1123 subdomain must consist of lower case
                    alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')","field":"metadata.name"}]},"code":422}\n'}
                    Traceback (most recent call last):
                      File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/_core.py", line 224, in submit_job
                        r.raise_for_status()
                      File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/httpx/_models.py", line 1507, in raise_for_status
                        raise HTTPStatusError(message, request=request, response=self)
                    httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 'http://localhost:8050/services/kbatch/jobs/'
                    For more information check: https://httpstatuses.com/422
Traceback (most recent call last):
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/bin/kbatch", line 33, in <module>
    sys.exit(load_entry_point('kbatch', 'console_scripts', 'kbatch')())
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/cli.py", line 157, in submit
    result = _core.submit_job(
  File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/_core.py", line 224, in submit_job
    r.raise_for_status()
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/httpx/_models.py", line 1507, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 'http://localhost:8050/services/kbatch/jobs/'
For more information check: https://httpstatuses.com/422

Closes #31.

Here's the CLI output now:

```console
❯ kbatch job submit --name=TEST --image="alpine"
[14:22:15] ERROR    {'detail': '{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Job.batch \\"TEST-6c6wr\\" is invalid: [metadata.generateName: Invalid value: \\"TEST-\\": a DNS-1123 subdomain must consist of lower case         _core.py:226
                    alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\'), metadata.name:
                    Invalid value: \\"TEST-6c6wr\\": a DNS-1123 subdomain must consist of lower case alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')]","reason":"Invalid","details":{"name":"TEST-6c6wr","group":"batch","kind":"Job","causes":[{"reason":"FieldValueInvalid","message":"Invalid value: \\"TEST-\\": a
                    DNS-1123 subdomain must consist of lower case alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')","field":"metadata.generateName"},{"reason":"FieldValueInvalid","message":"Invalid value: \\"TEST-6c6wr\\": a DNS-1123 subdomain must consist of lower case
                    alphanumeric characters, \'-\' or \'.\', and must start and end with an alphanumeric character (e.g. \'example.com\', regex used for validation is
                    \'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\')","field":"metadata.name"}]},"code":422}\n'}
                    Traceback (most recent call last):
                      File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/_core.py", line 224, in submit_job
                        r.raise_for_status()
                      File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/httpx/_models.py", line 1507, in raise_for_status
                        raise HTTPStatusError(message, request=request, response=self)
                    httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 'http://localhost:8050/services/kbatch/jobs/'
                    For more information check: https://httpstatuses.com/422
Traceback (most recent call last):
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/bin/kbatch", line 33, in <module>
    sys.exit(load_entry_point('kbatch', 'console_scripts', 'kbatch')())
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/cli.py", line 157, in submit
    result = _core.submit_job(
  File "/home/taugspurger/src/kbatch-dev/kbatch/kbatch/kbatch/_core.py", line 224, in submit_job
    r.raise_for_status()
  File "/home/taugspurger/miniconda3/envs/ksubmit-server/lib/python3.9/site-packages/httpx/_models.py", line 1507, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '422 Unprocessable Entity' for url 'http://localhost:8050/services/kbatch/jobs/'
For more information check: https://httpstatuses.com/422
```

Closes kbatch-dev#31.
@TomAugspurger TomAugspurger merged commit 5a2fd05 into kbatch-dev:main Mar 23, 2022
@TomAugspurger TomAugspurger deleted the fix/reraise-exceptions branch March 23, 2022 19:32
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.

can't submit job when name has upper-case letters
1 participant