MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Only

Method Only

app/controlplane/pkg/data/ent/workflow_query.go:305–318  ·  view source on GitHub ↗

Only returns a single Workflow entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Workflow entity is found. Returns a *NotFoundError when no Workflow entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

303// Returns a *NotSingularError when more than one Workflow entity is found.
304// Returns a *NotFoundError when no Workflow entities are found.
305func (_q *WorkflowQuery) Only(ctx context.Context) (*Workflow, error) {
306 nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
307 if err != nil {
308 return nil, err
309 }
310 switch len(nodes) {
311 case 1:
312 return nodes[0], nil
313 case 0:
314 return nil, &NotFoundError{workflow.Label}
315 default:
316 return nil, &NotSingularError{workflow.Label}
317 }
318}
319
320// OnlyX is like Only, but panics if an error occurs.
321func (_q *WorkflowQuery) OnlyX(ctx context.Context) *Workflow {

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected