createMessage method

String createMessage( {
  1. required String errorPrefix,
})
inherited

Generates a specific error message.

Returns a concise default message or a structured detailed message based on the presence of message. errorPrefix is determined by the nature of the concrete class, such as Exception or Error.

구체적인 에러 메시지를 생성합니다.

message의 유무에 따라 간결한 기본 메시지 또는 구조화된 상세 메시지를 반환합니다. errorPrefixException 또는 Error와 같이 구체 클래스의 성격에 따라 결정됩니다.

Implementation

String createMessage({required String errorPrefix}) {
  // 1. 타입 정보 구성
  final String typeInfo = switch (value.runtimeType.toString() == T.toString()) {
    true => '($T)',
    false => '(${value.runtimeType} as $T)',
  };

  // 2. 메시지 존재 여부 및 바디 구성
  final bool hasEnglish = message.english.isNotEmpty;
  final bool hasLocale = message.locale?.isNotEmpty ?? false;
  final bool messageIsEmpty = !hasEnglish && !hasLocale;

  // 3. 메시지 바디 조립
  final List<String> bodyParts = [
    '[English] ${message.english}',
    if (hasLocale) '[Locale] ${message.locale}',
  ];
  final String messageBody = bodyParts.join('\n');

  // 4. 최종 결과 반환
  return switch (messageIsEmpty) {
    true => '$prefix: Failed to parse $value $typeInfo',
    false => '$prefix$errorPrefix: value = $value $typeInfo\n$messageBody',
  };
}