Skip to content

[Code Quality] ServiceMapper.ToDomain — RecoveryAction default hardcoded as 'RecoveryAction.RestartService' instead of using 'AppConfig.DefaultRecoveryAction' #892

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info (DRY / inconsistency — silently breaks if DefaultRecoveryAction is ever changed)

File / line: src/Servy.Core/Mappers/ServiceMapper.cs line 133

Code:

// Validate Enum ranges
RecoveryAction = ConfigParser.ParseEnum(dto.RecoveryAction, RecoveryAction.RestartService),
//                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                                                          hardcoded literal

What's wrong: This is the only field-default in ServiceMapper.ToDomain that does not route through AppConfig. Every neighboring line uses an AppConfig.Default* constant — e.g. AppConfig.DefaultStartupType, AppConfig.DefaultPriority, AppConfig.DefaultDateRotationType, AppConfig.DefaultEnableRotation, AppConfig.DefaultMaxRestartAttempts — and AppConfig.cs already defines:

public const RecoveryAction DefaultRecoveryAction = RecoveryAction.RestartService;   // AppConfig.cs:308

Today the literal happens to equal the constant, so behavior is identical. But if a future maintainer flips the policy default to RecoveryAction.None (or anything else) in AppConfig.DefaultRecoveryAction, this one mapper line will silently keep falling back to RestartService — and the discrepancy will only surface as "newly-imported services from corrupt rows still get RestartService despite the new default."

This is the same class of bug as #845 (DefaultRotationSize is duplicated between AppConfig and Logger (DRY)), just in the mapper.

Suggested fix:

RecoveryAction = ConfigParser.ParseEnum(dto.RecoveryAction, AppConfig.DefaultRecoveryAction),

Same one-line change pattern as the surrounding AppConfig.Default* references.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions