diff options
| author | 2024-01-29 18:49:01 +0800 | |
|---|---|---|
| committer | 2024-01-29 18:49:01 +0800 | |
| commit | 71aae9010faad7504af0b299dd0b268cff42a499 (patch) | |
| tree | 85a5e74930b0cc12ad5e33f32191058d1928ce94 | |
| parent | 568bb2195ce5d9092f05a960e6e937bcd0d8d1ca (diff) | |
| download | infini-71aae9010faad7504af0b299dd0b268cff42a499.tar.gz infini-71aae9010faad7504af0b299dd0b268cff42a499.zip | |
feat(core): add type checking to handle mismatch returns
| -rw-r--r-- | src/infini/core.py | 3 | ||||
| -rw-r--r-- | src/infini/exceptions.py | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/infini/core.py b/src/infini/core.py index 87066370..552d9bf2 100644 --- a/src/infini/core.py +++ b/src/infini/core.py @@ -4,6 +4,7 @@ from infini.generator import TextGenerator from infini.handler import Handler from infini.output import Output from infini.typing import Any, Generator +from infini.exceptions import ValueError class Core: @@ -22,6 +23,8 @@ class Core: input = pre_intercepted_stream for handled_stream in self.handle(input): + if not isinstance(handled_stream, Output): + raise ValueError("Handler functions should return or yield a `Output` object.") if handled_stream.is_empty(): return outcome = self.generate(handled_stream) diff --git a/src/infini/exceptions.py b/src/infini/exceptions.py index 8bc9ceb4..37386ce3 100644 --- a/src/infini/exceptions.py +++ b/src/infini/exceptions.py @@ -8,3 +8,7 @@ class KeyError(InfiniException): class UnknownEvent(InfiniException): """文本事件不存在""" + + +class ValueError(InfiniException, ValueError): + """错误的数据""" |
