Files
VolcanicAgenticCore/extensions/Volcanic.AgenticCore.Extensions.ClaudeCode/ClaudeCodeException.cs

37 lines
1.9 KiB
C#

namespace Volcanic.AgenticCore.Extensions.ClaudeCode;
/// <summary>A typed failure of the Claude Code transport. <see cref="Code"/> is stable and machine-readable.</summary>
public sealed class ClaudeCodeException(string code, string message, bool retryable = false) : Exception(message)
{
public string Code { get; } = code;
/// <summary>True when repeating the request from the unchanged context can succeed (a mid-stream interruption).</summary>
public bool Retryable { get; } = retryable;
/// <summary>
/// The message the provider publishes: <c>[code] message</c>, except that a context overflow keeps its
/// <c>context_length_exceeded:</c> prefix intact because the core's retry policy keys on it.
/// </summary>
public string FormatForUser() => Code == Codes.ContextOverflow ? Message : $"[{Code}] {Message}";
public static class Codes
{
public const string ExecutableMissing = "executable_missing";
public const string Auth = "auth";
public const string ProtocolInit = "protocol_init";
public const string ProtocolStream = "protocol_stream";
public const string McpStartup = "mcp_startup";
public const string McpExecution = "mcp_execution";
public const string ToolUnknown = "tool_unknown";
public const string StreamInterrupted = "stream_interrupted";
public const string WorkingDirectory = "working_directory";
public const string ProcessExit = "process_exit";
public const string Timeout = "timeout";
public const string ContextOverflow = "context_overflow";
/// <summary>The context or tool declarations handed to the provider had a shape it cannot serialise.</summary>
public const string ContentShape = "content_shape";
/// <summary>An image could not be attached (type, encoding, size, count or path).</summary>
public const string Image = "image";
}
}