The deletion gate for the UI Service (archie-core-8cda.5.6) is objective: go list -deps from cmd/archie-ui must show no SQL/store implementation. internal/store's hand-written contract surfaces (TaskStore and its component interfaces, CaptureStore, MappingStore, BindingStore, BindingDispatcher, BindingTaskCreator, ConfigSnapshotStore) move to internal/contracts/store/v1 (package storev1), alongside the value types they carry (CapturedEvent, ConfigSnapshot, WorkflowStat, StageStat, DayTokens) and the sentinel errors -- whose canonical message strings are the wire contract and are byte-identical after the move. internal/store keeps type aliases, so daemon-side callers (archied, the daemon, staterpc's server side, taskactions) are unaffected. The UI-facing packages switch to storev1 directly: webui, archieui, captureintake, gatewayrpc, and staterpc's client/values -- which drops internal/store and modernc.org/sqlite from the archie-ui binary's import closure. overlay.DeniedKeys moves to internal/infrastructure/configuration for the same reason: webui referenced the constant and that dragged the overlay package's SQLite store in. The chat-contract and remaining runtime-handle decoupling continues under the same bead.
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package gatewayrpc
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
|
)
|
|
|
|
// taskActionCodes pairs each sentinel the daemon's action service reports
|
|
// with the gRPC code that carries it. The dashboard picks its HTTP status by
|
|
// matching these (404, 409, 503), and gRPC transports a code and a string,
|
|
// not a Go error, so the class travels as the code and is restored on
|
|
// arrival. Adding a sentinel a caller matches on without adding it here
|
|
// silently degrades that case to a 500.
|
|
var taskActionCodes = []struct {
|
|
code codes.Code
|
|
err error
|
|
}{
|
|
{code: codes.NotFound, err: taskactions.ErrNotFound},
|
|
{code: codes.FailedPrecondition, err: taskactions.ErrConflict},
|
|
{code: codes.Aborted, err: storev1.ErrStaleTransition},
|
|
{code: codes.Unavailable, err: taskactions.ErrUnavailable},
|
|
}
|
|
|
|
// taskActionStatus classifies an action error for the wire, keeping the
|
|
// daemon's own wording as the status message.
|
|
func taskActionStatus(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
for _, candidate := range taskActionCodes {
|
|
if errors.Is(err, candidate.err) {
|
|
return status.Error(candidate.code, err.Error())
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
// remoteTaskActionError restores a classified error on the caller's side,
|
|
// keeping the message the daemon produced.
|
|
type remoteTaskActionError struct {
|
|
message string
|
|
sentinel error
|
|
}
|
|
|
|
func (e remoteTaskActionError) Error() string { return e.message }
|
|
func (e remoteTaskActionError) Unwrap() error { return e.sentinel }
|
|
|
|
// taskActionError is taskActionStatus's inverse. A code with no sentinel
|
|
// behind it (including a transport failure) is returned untouched, so an
|
|
// unclassified failure stays a server error rather than being dressed up as
|
|
// a known one.
|
|
func taskActionError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
reported, ok := status.FromError(err)
|
|
if !ok {
|
|
return err
|
|
}
|
|
for _, candidate := range taskActionCodes {
|
|
if reported.Code() == candidate.code {
|
|
return remoteTaskActionError{message: reported.Message(), sentinel: candidate.err}
|
|
}
|
|
}
|
|
return err
|
|
}
|