beads/internal/storage/issueops/errors.go
CI Bot 927f943572 feat(issueops): name the two dependency-endpoint refusals (bd-yby99.9)
DependencyEditor.AddDependencies refuses an edge whose SOURCE names no row,
and one whose TARGET names no row this database can see the absence of. Every
other refusal the role can raise hands a caller something to branch on —
ErrSelfDependency, ErrDependencyCycle, *DependencyTypeConflictError,
*DependencyHierarchyConflictError — and these two handed back "an error", with
different text on each backend. A programmatic consumer could not tell a ghost
endpoint from an infrastructure failure, and the role's own doc said so rather
than promising the anonymity would last.

Both now carry an identity: ErrDependencySourceNotFound and
ErrDependencyTargetNotFound, wrapped by a *DependencyEndpointNotFoundError that
names the refused edge and which of its endpoints was absent. Two sentinels
rather than one because the two are separate answers — a ghost source is always
a bad id, while a target is refused only where this database would have held
it. What is NOT refused is unchanged: an "external:" reference and another
repository's id are still stored as external targets.

The store-backed body and the cross-tier target precheck mint the refusal where
they already read the row. The domain repository has no such read: it learns of
the absence from a foreign-key violation, so it reads both endpoints back on
the transaction that refused, only on the refusal path, and never downgrades
the refusal to a probe's failure. Taking the identity out of the driver's
constraint name would have been the thing a typed refusal exists to avoid. One
user-visible consequence: the proxied-server path now renders "issue <id> not
found" where it used to render a raw foreign-key violation, which is what the
embedded path has always said.

The guarded create classifies the new type where it classified the raw
foreign-key signal, so a missing dependency, parent or waits-for target is
still ErrValidation wrapping ErrNotFound on every backend.

RemoveDependency is deliberately untouched. A removal that finds no edge is
Removed false with a nil error, so there is no refusal there to name.

The shared contract asserts the sentinel and the typed fields for each endpoint
in TWO POSITIONS: alone in a request, and mid-batch where the refusal competes
with the rollback of an edge already written, the half that also reads the
graph back at zero edges. Both cases were verified red on all three backends
before the production change — "issue <id> not found" untyped on the two store
paths, "Error 1452 ... Foreign key violation" on the unit-of-work path.

Agent-Signature: claude-code-claude-opus-5-unknown-reasoning on behalf of CI Bot

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 19:45:54 +00:00

62 lines
2.2 KiB
Go

package issueops
import (
"fmt"
publicops "github.com/steveyegge/beads/issueops"
)
// MissingDependencySource builds the refusal for an edge whose SOURCE names no
// row this database holds.
//
// Every write plumbing that can observe the absence mints its refusal here or
// in the target twin below: the in-transaction store body, the cross-tier
// target precheck, and the domain repository's classification of a foreign-key
// refusal. That is what makes the message identical across them as well as the
// type.
func MissingDependencySource(issueID, dependsOnID string) error {
return &publicops.DependencyEndpointNotFoundError{
IssueID: issueID,
DependsOnID: dependsOnID,
MissingID: issueID,
Err: publicops.ErrDependencySourceNotFound,
}
}
// MissingDependencyTarget builds the refusal for an edge whose TARGET names no
// row this database holds and whose absence this database can see. Callers
// decide that second half — an "external:" reference and another repository's
// id never reach here.
func MissingDependencyTarget(issueID, dependsOnID string) error {
return &publicops.DependencyEndpointNotFoundError{
IssueID: issueID,
DependsOnID: dependsOnID,
MissingID: dependsOnID,
Err: publicops.ErrDependencyTargetNotFound,
}
}
// ErrTooManyRows is returned by SearchIssuesInTx (and equivalent paths in
// other backends) when a search would yield more rows than the caller's
// MaxRows cap allows. Callers can match it with errors.As to surface a
// structured "result set too large" condition instead of an opaque error
// string.
//
// Found is the row count observed when the cap fired. The storage layer
// issues LIMIT MaxRows+1 to detect overage, so Found equals MaxRows+1 in
// practice; the true row count in the underlying data may be larger.
//
// Source attributes which knob set MaxRows. Expected values: "--max-rows",
// "BEADS_MAX_ROWS", or "" (library users with no source attribution).
type ErrTooManyRows struct {
Found int
Cap int
Source string
}
func (e *ErrTooManyRows) Error() string {
if e.Source != "" {
return fmt.Sprintf("search returned %d rows, exceeding %s cap of %d", e.Found, e.Source, e.Cap)
}
return fmt.Sprintf("search returned %d rows, exceeding cap of %d", e.Found, e.Cap)
}