InvokeAI/invokeai/app/services/shared
psychedelicious 25b9c19eed feat(app): handle preparation errors as node errors
We were not handling node preparation errors as node errors before. Here's the explanation, copied from a comment that is no longer required:

---

TODO(psyche): Sessions only support errors on nodes, not on the session itself. When an error occurs outside
node execution, it bubbles up to the processor where it is treated as a queue item error.

Nodes are pydantic models. When we prepare a node in `session.next()`, we set its inputs. This can cause a
pydantic validation error. For example, consider a resize image node which has a constraint on its `width`
input field - it must be greater than zero. During preparation, if the width is set to zero, pydantic will
raise a validation error.

When this happens, it breaks the flow before `invocation` is set. We can't set an error on the invocation
because we didn't get far enough to get it - we don't know its id. Hence, we just set it as a queue item error.

---

This change wraps the node preparation step with exception handling. A new `NodeInputError` exception is raised when there is a validation error. This error has the node (in the state it was in just prior to the error) and an identifier of the input that failed.

This allows us to mark the node that failed preparation as errored, correctly making such errors _node_ errors and not _processor_ errors. It's much easier to diagnose these situations. The error messages look like this:

> Node b5ac87c6-0678-4b8c-96b9-d215aee12175 has invalid incoming input for height

Some of the exception handling logic is cleaned up.
2024-05-24 20:02:24 +10:00
..
sqlite feat(db): add migration 9 - empty session queue 2024-04-02 13:25:14 +11:00
sqlite_migrator fix ruff issues 2024-04-12 07:19:16 +10:00
__init__.py feat(backend): organise service dependencies 2023-10-12 12:15:06 -04:00
graph.py feat(app): handle preparation errors as node errors 2024-05-24 20:02:24 +10:00
invocation_context.py feat(app): simplified create image API 2024-05-18 09:04:37 +10:00
pagination.py feat(api): chore: pydantic & fastapi upgrade 2023-10-17 14:59:25 +11:00