Files
dify/api/services/dify_builder/errors.py
Charles YaoandClaude Opus 5 b7017aa363 fix(dify-builder): tell a draft that would not start apart from a stale fix
apply_repair's preflight raises PreflightError when the graph it is about
to write would fail at Graph.init. Every handler caught it as a plain
ValueError, so the five apply sites could not tell it apart from a
graph_ops rejection:

- plan approval (Build, Edit) called ANY ValueError "The workflow can't
  start", including "node not found: x", sending the user hunting for a
  broken node that does not exist;
- the repair-apply gates (Build/Edit await_repair, Fix apply) called a
  preflight rejection "The proposed fix no longer applies to the current
  draft" -- the fix applied fine; it would leave an unstartable draft.

Add core DraftWouldNotStartError(ValueError) and make PreflightError
subclass it (services imports core; core still imports no services).
Each site now catches it before the ValueError branch, with the same
control flow and the true reason: plan approval keeps "The workflow
can't start" for it and says "Couldn't apply the workflow" otherwise;
the repair gates say "The workflow can't start" for it and keep
"Couldn't apply the fix" otherwise. The shared card/turn construction is
factored (_graph_not_applied, _change_not_applied, and
drop_unapplied_repair in handlers_fix) and the new literals are
catalogued in strings.py.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 22:57:33 -07:00

33 lines
1.3 KiB
Python

"""Domain errors raised by the Dify Builder's Dify-service adapter.
These sit alongside (not instead of) ``core.dify_builder.errors`` --
they're specific to the OSS ``WorkflowService`` surface the adapter wraps,
so they live in this package rather than the I/O-free ``core`` layer.
"""
from core.dify_builder.errors import DraftWouldNotStartError
class WorkflowNotInitializedError(Exception):
"""Raised when an app has no draft workflow yet (``get_draft_workflow`` returns ``None``)."""
class HashMismatchError(Exception):
"""Domain re-map of ``services.errors.app.WorkflowHashNotEqualError``.
Raised when ``sync_draft_workflow``'s optimistic-concurrency check finds
the draft graph changed since it was last read. The adapter (Task 4)
catches the OSS error and re-raises this instead, so callers only need
to know about ``core``/``services.dify_builder`` error types.
"""
class PreflightError(DraftWouldNotStartError):
"""Raised by ``apply_repair`` when the graph it was about to write would
not start: ``services.dify_builder.preflight.preflight_errors`` found a
node ``Graph.init`` would reject. Subclasses the core
``DraftWouldNotStartError`` so the handlers (which cannot import
``services``) can tell it apart from a stale intent; still a
``ValueError`` underneath.
"""