using System;
using System.Runtime.Serialization;
namespace MarketAlly.AIPlugin.Learning.Exceptions
{
///
/// Base exception for all learning-related operations
///
public abstract class LearningException : Exception
{
protected LearningException() { }
protected LearningException(string message) : base(message) { }
protected LearningException(string message, Exception innerException) : base(message, innerException) { }
protected LearningException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
///
/// Exception thrown when compilation fails during learning iteration
///
public class CompilationException : LearningException
{
public int ErrorCount { get; }
public int WarningCount { get; }
public string[] Errors { get; }
public CompilationException(int errorCount, int warningCount, string[] errors)
: base($"Compilation failed with {errorCount} errors and {warningCount} warnings")
{
ErrorCount = errorCount;
WarningCount = warningCount;
Errors = errors ?? Array.Empty();
}
public CompilationException(string message, int errorCount, int warningCount, Exception innerException = null)
: base(message, innerException)
{
ErrorCount = errorCount;
WarningCount = warningCount;
Errors = Array.Empty();
}
}
///
/// Exception thrown when RefactorIQ operations fail
///
public class RefactorIQException : LearningException
{
public string Operation { get; }
public RefactorIQException(string operation, string message)
: base($"RefactorIQ {operation} failed: {message}")
{
Operation = operation;
}
public RefactorIQException(string operation, string message, Exception innerException)
: base($"RefactorIQ {operation} failed: {message}", innerException)
{
Operation = operation;
}
}
///
/// Exception thrown when learning iteration encounters critical errors
///
public class LearningIterationException : LearningException
{
public int IterationNumber { get; }
public string Phase { get; }
public LearningIterationException(int iterationNumber, string phase, string message)
: base($"Learning iteration {iterationNumber} failed in {phase}: {message}")
{
IterationNumber = iterationNumber;
Phase = phase;
}
public LearningIterationException(int iterationNumber, string phase, string message, Exception innerException)
: base($"Learning iteration {iterationNumber} failed in {phase}: {message}", innerException)
{
IterationNumber = iterationNumber;
Phase = phase;
}
}
///
/// Exception thrown when Git operations fail
///
public class GitOperationException : LearningException
{
public string Operation { get; }
public string RepositoryPath { get; }
public GitOperationException(string operation, string repositoryPath, string message)
: base($"Git {operation} failed in {repositoryPath}: {message}")
{
Operation = operation;
RepositoryPath = repositoryPath;
}
public GitOperationException(string operation, string repositoryPath, string message, Exception innerException)
: base($"Git {operation} failed in {repositoryPath}: {message}", innerException)
{
Operation = operation;
RepositoryPath = repositoryPath;
}
}
///
/// Exception thrown when AI services fail
///
public class AIServiceException : LearningException
{
public string ServiceName { get; }
public bool IsRetryable { get; }
public AIServiceException(string serviceName, string message, bool isRetryable = true)
: base($"AI service {serviceName} failed: {message}")
{
ServiceName = serviceName;
IsRetryable = isRetryable;
}
public AIServiceException(string serviceName, string message, Exception innerException, bool isRetryable = true)
: base($"AI service {serviceName} failed: {message}", innerException)
{
ServiceName = serviceName;
IsRetryable = isRetryable;
}
}
///
/// Exception thrown when configuration is invalid
///
public class ConfigurationException : LearningException
{
public string ConfigurationKey { get; }
public ConfigurationException(string configurationKey, string message)
: base($"Configuration error for '{configurationKey}': {message}")
{
ConfigurationKey = configurationKey;
}
public ConfigurationException(string configurationKey, string message, Exception innerException)
: base($"Configuration error for '{configurationKey}': {message}", innerException)
{
ConfigurationKey = configurationKey;
}
}
///
/// Exception thrown when security validation fails
///
public class SecurityException : LearningException
{
public string Operation { get; }
public string Resource { get; }
public SecurityException(string operation, string resource, string message)
: base($"Security violation in {operation} for {resource}: {message}")
{
Operation = operation;
Resource = resource;
}
}
}