Skip to content

Commit 825f9b2

Browse files
authored
fix(go): include registered schemes in facilitator error messages (x402-foundation#1712)
When Verify or Settle fails to find a matching facilitator for a scheme/network pair, the error now lists all registered scheme/network combinations. This helps users quickly identify misconfiguration (e.g., wrong network name, missing registration) without having to inspect the facilitator setup code. Before: no facilitator for scheme exact on network eip155:1 After: no facilitator for scheme "exact" on network "eip155:1"; registered: exact@eip155:8453, exact@eip155:84532 Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent 0b33634 commit 825f9b2

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

go/facilitator.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ func (f *x402Facilitator) verifyV1(ctx context.Context, payload types.PaymentPay
435435
}
436436
}
437437

438-
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %s on network %s", scheme, network))
438+
registered := f.registeredV1Summary()
439+
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
439440
}
440441

441442
// verifyV2 verifies a V2 payment (internal, typed)
@@ -460,7 +461,8 @@ func (f *x402Facilitator) verifyV2(ctx context.Context, payload types.PaymentPay
460461
}
461462
}
462463

463-
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %s on network %s", scheme, network))
464+
registered := f.registeredV2Summary()
465+
return nil, NewVerifyError(ErrNoFacilitatorForNetwork, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
464466
}
465467

466468
// settleV1 settles a V1 payment (internal, typed)
@@ -485,7 +487,8 @@ func (f *x402Facilitator) settleV1(ctx context.Context, payload types.PaymentPay
485487
}
486488
}
487489

488-
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %s on network %s", scheme, network))
490+
registered := f.registeredV1Summary()
491+
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
489492
}
490493

491494
// settleV2 settles a V2 payment (internal, typed)
@@ -510,7 +513,38 @@ func (f *x402Facilitator) settleV2(ctx context.Context, payload types.PaymentPay
510513
}
511514
}
512515

513-
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %s on network %s", scheme, network))
516+
registered := f.registeredV2Summary()
517+
return nil, NewSettleError(ErrNoFacilitatorForNetwork, "", network, "", fmt.Sprintf("no facilitator for scheme %q on network %q; registered: %s", scheme, network, registered))
518+
}
519+
520+
// registeredV1Summary returns a human-readable list of registered V1 scheme/network pairs.
521+
func (f *x402Facilitator) registeredV1Summary() string {
522+
if len(f.schemesV1) == 0 {
523+
return "(none)"
524+
}
525+
var parts []string
526+
for _, data := range f.schemesV1 {
527+
facilitator := data.facilitator.(SchemeNetworkFacilitatorV1)
528+
for network := range data.networks {
529+
parts = append(parts, fmt.Sprintf("%s@%s", facilitator.Scheme(), network))
530+
}
531+
}
532+
return strings.Join(parts, ", ")
533+
}
534+
535+
// registeredV2Summary returns a human-readable list of registered V2 scheme/network pairs.
536+
func (f *x402Facilitator) registeredV2Summary() string {
537+
if len(f.schemes) == 0 {
538+
return "(none)"
539+
}
540+
var parts []string
541+
for _, data := range f.schemes {
542+
facilitator := data.facilitator.(SchemeNetworkFacilitator)
543+
for network := range data.networks {
544+
parts = append(parts, fmt.Sprintf("%s@%s", facilitator.Scheme(), network))
545+
}
546+
}
547+
return strings.Join(parts, ", ")
514548
}
515549

516550
// GetSupported returns supported payment kinds

0 commit comments

Comments
 (0)