mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 11:55:45 +00:00
adding latest
This commit is contained in:
39
dev/notes/custom_exceptions.md
Normal file
39
dev/notes/custom_exceptions.md
Normal file
@@ -0,0 +1,39 @@
|
||||
Custom exceptions
|
||||
|
||||
Create an `./exceptions.py`.
|
||||
|
||||
Define any custom exceptions. Can append `Error` to the exception name if needed, otherwise be descriptive.
|
||||
|
||||
E.g `MismatchedTokenError`, `ScopedPageAlreadyExists`.
|
||||
|
||||
(If it would raise a `SystemExit(1)` use an Error).
|
||||
|
||||
|
||||
Can set custom attributes on the Exception:
|
||||
|
||||
```
|
||||
class MismatchedTokenError(Exception):
|
||||
def __init__(self, expected: int, given: int) -> None:
|
||||
self.expected = expected
|
||||
self.given = given
|
||||
super().__init__()
|
||||
```
|
||||
|
||||
Can refer to these when capturing the exception:
|
||||
|
||||
```
|
||||
except exceptions.MismatchedTokenError as exec_info:
|
||||
click.echo(exec_info.expected, exec_info.given)
|
||||
# error handling
|
||||
```
|
||||
|
||||
Alternatively you can pass arbitrary `*args` into the exceptions and capture them with `args[0]`:
|
||||
|
||||
```
|
||||
raise exceptions.TemplateNotFoundError("some message")
|
||||
```
|
||||
|
||||
```
|
||||
except exceptions.TemplateFileNotFoundError as exec_info:
|
||||
cli_message(exec_info.args[0])
|
||||
```
|
||||
@@ -1,39 +0,0 @@
|
||||
# testing notes
|
||||
|
||||
## options
|
||||
|
||||
optional:
|
||||
|
||||
- user_input
|
||||
- example
|
||||
- template_filename
|
||||
- template_path
|
||||
|
||||
required:
|
||||
|
||||
- base_path
|
||||
- page_path
|
||||
- filename
|
||||
- extension
|
||||
- name
|
||||
|
||||
## tests to write
|
||||
|
||||
- user input does not match number of input tokens
|
||||
- no user input
|
||||
- mismatched user input
|
||||
- with/without example
|
||||
|
||||
- dry run
|
||||
|
||||
## tests done
|
||||
|
||||
- path/page filenames can contain spaces and they are converted
|
||||
- user input is None
|
||||
- page using/not using input tokens
|
||||
- page using/not using date tokens
|
||||
- page using/not using name tokens
|
||||
- page with/without a template
|
||||
- the given base path does not exist
|
||||
- the given template file does not exist
|
||||
- page already exists
|
||||
Reference in New Issue
Block a user