| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Providers; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Thrown by <see cref="ITieredProviderSelector{TQuery, TResult}"/> when at least one |
| | | 5 | | /// provider was registered but every provider failed or was denied by the quota gate. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <remarks> |
| | | 8 | | /// Inherits from <see cref="NoProvidersAvailableException"/> so callers can choose to |
| | | 9 | | /// catch the base type for both "no providers registered" and "all providers failed" |
| | | 10 | | /// conditions, or catch this type specifically. |
| | | 11 | | /// </remarks> |
| | | 12 | | public sealed class AllProvidersFailedException : NoProvidersAvailableException |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the per-provider attempt diagnostics in the order they were tried. |
| | | 16 | | /// Each entry describes one provider's outcome (e.g., quota denial or unavailability reason). |
| | | 17 | | /// </summary> |
| | 10 | 18 | | public IReadOnlyList<string> Attempts { get; } |
| | | 19 | | |
| | | 20 | | /// <param name="attempts"> |
| | | 21 | | /// Per-provider attempt diagnostics in the order providers were tried. |
| | | 22 | | /// </param> |
| | | 23 | | public AllProvidersFailedException(IReadOnlyList<string> attempts) |
| | 9 | 24 | | : base(BuildMessage(attempts)) |
| | | 25 | | { |
| | 8 | 26 | | ArgumentNullException.ThrowIfNull(attempts); |
| | 8 | 27 | | Attempts = attempts; |
| | 8 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <param name="attempts"> |
| | | 31 | | /// Per-provider attempt diagnostics in the order providers were tried. |
| | | 32 | | /// </param> |
| | | 33 | | /// <param name="innerException">The underlying exception that caused this failure, if any.</param> |
| | | 34 | | public AllProvidersFailedException(IReadOnlyList<string> attempts, Exception? innerException) |
| | 1 | 35 | | : base(BuildMessage(attempts), innerException) |
| | | 36 | | { |
| | 1 | 37 | | ArgumentNullException.ThrowIfNull(attempts); |
| | 1 | 38 | | Attempts = attempts; |
| | 1 | 39 | | } |
| | | 40 | | |
| | | 41 | | private static string BuildMessage(IReadOnlyList<string> attempts) |
| | | 42 | | { |
| | 10 | 43 | | ArgumentNullException.ThrowIfNull(attempts); |
| | 9 | 44 | | return $"All providers failed. Attempts: [{string.Join("; ", attempts)}]"; |
| | | 45 | | } |
| | | 46 | | } |