Refactor exceptions to include profileId context
Refactored `JobException` and derived classes (`InactiveProfileException`, `JobHttpException`, `JobSqlException`) to include `profileId` as a required parameter in their constructors. This ensures consistent context for exceptions related to job execution. Updated behaviors (`CheckQueryExecutionBehavior`, `MainQueryExecutionBehavior`, `ReCRequestExecutionBehavior`) to use the new constructors, passing `profileId` where applicable. Improved exception messages for better debugging context. Simplified property initialization and enhanced XML documentation for clarity.
This commit is contained in:
@@ -6,33 +6,30 @@ namespace ECMJobRunner.Application.Common.Exceptions
|
||||
/// Exception for SQL query execution failures
|
||||
/// Extends JobException with SQL query context for debugging
|
||||
/// </summary>
|
||||
public class JobSqlException : JobException
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of JobSqlException with SQL query context
|
||||
/// </remarks>
|
||||
/// <param name="profileId">Identifier of the profile associated with the job</param>
|
||||
/// <param name="jobName">Name of the job that failed (e.g., "Main Query Execution", "Check Query")</param>
|
||||
/// <param name="processName">Name of the process/stage being executed</param>
|
||||
/// <param name="batchId">Unique batch identifier for tracking</param>
|
||||
/// <param name="reason">Human-readable reason for the failure (nullable)</param>
|
||||
/// <param name="query">The SQL query that failed (nullable, for debugging purposes)</param>
|
||||
/// <param name="innerException">The underlying SQL exception (nullable)</param>
|
||||
/// <remarks>
|
||||
/// Use this exception for SQL-related failures such as:
|
||||
/// - Main query execution errors
|
||||
/// - Check query validation failures
|
||||
/// - Database connection issues
|
||||
/// - SQL syntax errors
|
||||
/// - Query timeout exceptions
|
||||
///
|
||||
/// The Query property can be logged for debugging but should be handled carefully
|
||||
/// to avoid exposing sensitive data in production logs.
|
||||
/// </remarks>
|
||||
public class JobSqlException(long profileId, string jobName, string processName, string batchId, string? reason, string? query, Exception? innerException)
|
||||
: JobException(profileId, jobName, processName, batchId, reason, innerException, ("Query", query, true))
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of JobSqlException with SQL query context
|
||||
/// </summary>
|
||||
/// <param name="jobName">Name of the job that failed (e.g., "Main Query Execution", "Check Query")</param>
|
||||
/// <param name="processName">Name of the process/stage being executed</param>
|
||||
/// <param name="batchId">Unique batch identifier for tracking</param>
|
||||
/// <param name="reason">Human-readable reason for the failure (nullable)</param>
|
||||
/// <param name="query">The SQL query that failed (nullable, for debugging purposes)</param>
|
||||
/// <param name="innerException">The underlying SQL exception (nullable)</param>
|
||||
/// <remarks>
|
||||
/// Use this exception for SQL-related failures such as:
|
||||
/// - Main query execution errors
|
||||
/// - Check query validation failures
|
||||
/// - Database connection issues
|
||||
/// - SQL syntax errors
|
||||
/// - Query timeout exceptions
|
||||
///
|
||||
/// The Query property can be logged for debugging but should be handled carefully
|
||||
/// to avoid exposing sensitive data in production logs.
|
||||
/// </remarks>
|
||||
public JobSqlException(string jobName, string processName, string batchId, string? reason, string? query, Exception? innerException) : base(jobName, processName, batchId, reason, innerException,
|
||||
("Query", query, true))
|
||||
{
|
||||
Query = query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SQL query that failed (nullable)
|
||||
@@ -41,6 +38,6 @@ namespace ECMJobRunner.Application.Common.Exceptions
|
||||
/// This property is marked as virtual to allow derived classes to customize query handling
|
||||
/// (e.g., sanitizing sensitive data, truncating long queries)
|
||||
/// </remarks>
|
||||
public virtual string? Query { get; }
|
||||
public virtual string? Query { get; } = query;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user