Skip to content

Commit 2bd7c21

Browse files
committed
refactor(errors)!: ErrorCodeFieldNames → ErrorLogFieldNames + NumericCode/Kind 리네이밍
"ErrorCode" 접두사 오버로드 해소 최종 단계 + "ErrorType" 토큰 충돌 제거: 1. 로그 필드 상수 클래스 rename - ErrorCodeFieldNames → ErrorLogFieldNames (Serilog 특화 명시) - XML 주석 추가 — 관측성 소비자 마이그레이션 주의사항 명시 2. int 속성 rename (string ErrorCode와 구분 명확화) - ExpectedErrorBase.ErrorCodeId (int) → NumericCode - ExpectedError/ExpectedError<T>/... 4개 record 동일 rename 3. 로그 필드 이름·값 동기화 - ErrorLogFieldNames.ErrorType (value "ErrorType") → ErrorLogFieldNames.Kind (value "Kind") (ErrorKind 추상 record와 혼동 방지 + 네임 단축) - ErrorLogFieldNames.ErrorCodeId (value "ErrorCodeId") → ErrorLogFieldNames.NumericCode (value "NumericCode") 변경 파일: - Src/Functorium/Abstractions/Errors/ - ErrorCodeFieldNames.cs → ErrorLogFieldNames.cs (rename + Kind/NumericCode) - ExpectedErrorBase.cs, ExpectedError.cs (int 프로퍼티 rename) - ErrorFactory.cs (nameof 참조 갱신) - Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/ - IErrorDestructurer.cs + ErrorTypes/*Destructurer.cs (6개) 참조 갱신 - Tests/Functorium.Tests.Unit/AbstractionsTests/Errors/Snapshots/ ErrorDestructuring/*.verified.txt (11개) — ErrorType→Kind·ErrorCodeId→NumericCode + 알파벳 정렬 적용 BREAKING CHANGE: - Serilog 로그 필드명 변경: - ErrorType → Kind (value "ErrorType" → "Kind") - ErrorCodeId → NumericCode (value "ErrorCodeId" → "NumericCode") → 대시보드(Seq·Grafana·Elastic)에서 이 필드로 쿼리·알림 설정 중이면 마이그레이션 필요 - int 프로퍼티 rename: ExpectedError.ErrorCodeId → NumericCode (internal 타입; InternalsVisibleTo 범위의 Testing·Adapters만 영향) 참고: Docs.Site 가이드·VERIFICATION.md는 후속 커밋(Stage 5)에서 일괄 갱신.
1 parent 6627c7f commit 2bd7c21

22 files changed

Lines changed: 176 additions & 161 deletions

File tree

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
using Functorium.Abstractions.Errors;
2-
using Serilog.Core;
3-
using Serilog.Events;
4-
5-
namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies.ErrorTypes;
6-
7-
public class ExceptionalDestructurer : IErrorDestructurer
8-
{
9-
public bool CanHandle(Error error) =>
10-
error is Exceptional;
11-
12-
public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFactory factory)
13-
{
14-
Exceptional e = (Exceptional)error;
15-
16-
List<LogEventProperty> props =
17-
[
18-
new(ErrorCodeFieldNames.ErrorType, new ScalarValue(e.GetType().Name)),
19-
// ErrorCode
20-
new(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(e.Code))
21-
// ErrorCurrentValue
22-
// Message
23-
];
24-
25-
// ExceptionDetails
26-
e.Exception.IfSome(ex =>
27-
{
28-
props.Add(new(ErrorCodeFieldNames.ExceptionDetails, factory.CreatePropertyValue(ex, true)));
29-
});
30-
31-
return new StructureValue(props);
32-
}
33-
}
1+
using Functorium.Abstractions.Errors;
2+
using Serilog.Core;
3+
using Serilog.Events;
4+
5+
namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies.ErrorTypes;
6+
7+
public class ExceptionalDestructurer : IErrorDestructurer
8+
{
9+
public bool CanHandle(Error error) =>
10+
error is Exceptional;
11+
12+
public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFactory factory)
13+
{
14+
Exceptional e = (Exceptional)error;
15+
16+
List<LogEventProperty> props =
17+
[
18+
new(ErrorLogFieldNames.Kind, new ScalarValue(e.GetType().Name)),
19+
// ErrorCode
20+
new(ErrorLogFieldNames.NumericCode, new ScalarValue(e.Code))
21+
// ErrorCurrentValue
22+
// Message
23+
];
24+
25+
// ExceptionDetails
26+
e.Exception.IfSome(ex =>
27+
{
28+
props.Add(new(ErrorLogFieldNames.ExceptionDetails, factory.CreatePropertyValue(ex, true)));
29+
});
30+
31+
return new StructureValue(props);
32+
}
33+
}

Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/ErrorTypes/ExceptionalErrorDestructurer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFact
1515

1616
List<LogEventProperty> props =
1717
[
18-
new(ErrorCodeFieldNames.ErrorType, new ScalarValue(e.GetType().Name)),
19-
new(ErrorCodeFieldNames.ErrorCode, new ScalarValue(e.ErrorCode)),
20-
new(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(e.Code)),
18+
new(ErrorLogFieldNames.Kind, new ScalarValue(e.GetType().Name)),
19+
new(ErrorLogFieldNames.ErrorCode, new ScalarValue(e.ErrorCode)),
20+
new(ErrorLogFieldNames.NumericCode, new ScalarValue(e.Code)),
2121
// ErrorCurrentValue
22-
new(ErrorCodeFieldNames.Message, new ScalarValue(e.Message))
22+
new(ErrorLogFieldNames.Message, new ScalarValue(e.Message))
2323
];
2424

2525
e.Exception.IfSome(ex =>
2626
{
27-
props.Add(new(ErrorCodeFieldNames.ExceptionDetails, factory.CreatePropertyValue(ex, true)));
27+
props.Add(new(ErrorLogFieldNames.ExceptionDetails, factory.CreatePropertyValue(ex, true)));
2828
});
2929

3030
return new StructureValue(props);
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
using Functorium.Abstractions.Errors;
2-
using Serilog.Core;
3-
using Serilog.Events;
4-
5-
namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies.ErrorTypes;
6-
7-
public class ExpectedDestructurer : IErrorDestructurer
8-
{
9-
public bool CanHandle(Error error) =>
10-
error is Expected;
11-
12-
public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFactory factory)
13-
{
14-
Expected e = (Expected)error;
15-
List<LogEventProperty> props =
16-
[
17-
new(ErrorCodeFieldNames.ErrorType, new ScalarValue(e.GetType().Name)),
18-
// ErrorCode
19-
new(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(e.Code)),
20-
// ErrorCurrentValue
21-
new(ErrorCodeFieldNames.Message, new ScalarValue(e.Message))
22-
];
23-
24-
// InnerError
25-
e.Inner.IfSome(inner =>
26-
{
27-
props.Add(new(ErrorCodeFieldNames.InnerError, ErrorsDestructuringPolicy.DestructureError(inner, factory)));
28-
});
29-
30-
return new StructureValue(props);
31-
}
32-
}
1+
using Functorium.Abstractions.Errors;
2+
using Serilog.Core;
3+
using Serilog.Events;
4+
5+
namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies.ErrorTypes;
6+
7+
public class ExpectedDestructurer : IErrorDestructurer
8+
{
9+
public bool CanHandle(Error error) =>
10+
error is Expected;
11+
12+
public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFactory factory)
13+
{
14+
Expected e = (Expected)error;
15+
List<LogEventProperty> props =
16+
[
17+
new(ErrorLogFieldNames.Kind, new ScalarValue(e.GetType().Name)),
18+
// ErrorCode
19+
new(ErrorLogFieldNames.NumericCode, new ScalarValue(e.Code)),
20+
// ErrorCurrentValue
21+
new(ErrorLogFieldNames.Message, new ScalarValue(e.Message))
22+
];
23+
24+
// InnerError
25+
e.Inner.IfSome(inner =>
26+
{
27+
props.Add(new(ErrorLogFieldNames.InnerError, ErrorsDestructuringPolicy.DestructureError(inner, factory)));
28+
});
29+
30+
return new StructureValue(props);
31+
}
32+
}

Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/ErrorTypes/ExpectedErrorDestructurer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFact
1515

1616
List<LogEventProperty> props =
1717
[
18-
new(ErrorCodeFieldNames.ErrorType, new ScalarValue(e.GetType().Name)),
19-
new(ErrorCodeFieldNames.ErrorCode, new ScalarValue(e.ErrorCode)),
20-
new(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(e.Code)),
21-
new(ErrorCodeFieldNames.ErrorCurrentValue, new ScalarValue(e.ErrorCurrentValue)),
22-
new(ErrorCodeFieldNames.Message, new ScalarValue(e.Message))
18+
new(ErrorLogFieldNames.Kind, new ScalarValue(e.GetType().Name)),
19+
new(ErrorLogFieldNames.ErrorCode, new ScalarValue(e.ErrorCode)),
20+
new(ErrorLogFieldNames.NumericCode, new ScalarValue(e.Code)),
21+
new(ErrorLogFieldNames.ErrorCurrentValue, new ScalarValue(e.ErrorCurrentValue)),
22+
new(ErrorLogFieldNames.Message, new ScalarValue(e.Message))
2323
];
2424

2525
return new StructureValue(props);

Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/ErrorTypes/ExpectedErrorTDestructurer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFact
1818
Type type = error.GetType();
1919
List<LogEventProperty> props =
2020
[
21-
new(ErrorCodeFieldNames.ErrorType, new ScalarValue(type.Name)),
22-
new(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(error.Code))
21+
new(ErrorLogFieldNames.Kind, new ScalarValue(type.Name)),
22+
new(ErrorLogFieldNames.NumericCode, new ScalarValue(error.Code))
2323
];
2424

25-
string errorCode = type.GetProperty(ErrorCodeFieldNames.ErrorCode)?.GetValue(error)?.ToString()
26-
?? ErrorCodeFieldNames.UnknownErrorCode;
25+
string errorCode = type.GetProperty(ErrorLogFieldNames.ErrorCode)?.GetValue(error)?.ToString()
26+
?? ErrorLogFieldNames.UnknownErrorCode;
2727

28-
string message = type.GetProperty(ErrorCodeFieldNames.Message)?.GetValue(error)?.ToString()
29-
?? ErrorCodeFieldNames.UnknownErrorMessage;
28+
string message = type.GetProperty(ErrorLogFieldNames.Message)?.GetValue(error)?.ToString()
29+
?? ErrorLogFieldNames.UnknownErrorMessage;
3030

31-
props.Add(new(ErrorCodeFieldNames.ErrorCode, new ScalarValue(errorCode)));
32-
props.Add(new(ErrorCodeFieldNames.Message, new ScalarValue(message)));
31+
props.Add(new(ErrorLogFieldNames.ErrorCode, new ScalarValue(errorCode)));
32+
props.Add(new(ErrorLogFieldNames.Message, new ScalarValue(message)));
3333

3434
foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
35-
.Where(p => p.Name.StartsWith(ErrorCodeFieldNames.ErrorCurrentValue)))
35+
.Where(p => p.Name.StartsWith(ErrorLogFieldNames.ErrorCurrentValue)))
3636
{
3737
object? value = prop.GetValue(error);
3838
if (value is not null)

Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/ErrorTypes/ManyErrorsDestructurer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public LogEventPropertyValue Destructure(Error error, ILogEventPropertyValueFact
1919

2020
return new StructureValue(
2121
[
22-
new LogEventProperty(ErrorCodeFieldNames.ErrorType, new ScalarValue(e.GetType().Name)),
22+
new LogEventProperty(ErrorLogFieldNames.Kind, new ScalarValue(e.GetType().Name)),
2323
// ErrorCode
24-
new LogEventProperty(ErrorCodeFieldNames.ErrorCodeId, new ScalarValue(e.Code)),
24+
new LogEventProperty(ErrorLogFieldNames.NumericCode, new ScalarValue(e.Code)),
2525
// ErrorCurrentValue
2626
// Message
2727

28-
new LogEventProperty(ErrorCodeFieldNames.Count, new ScalarValue(e.Count)),
29-
new LogEventProperty(ErrorCodeFieldNames.Errors, new SequenceValue(nested))
28+
new LogEventProperty(ErrorLogFieldNames.Count, new ScalarValue(e.Count)),
29+
new LogEventProperty(ErrorLogFieldNames.Errors, new SequenceValue(nested))
3030
]);
3131
}
3232
}

Src/Functorium.Adapters/Abstractions/Errors/DestructuringPolicies/IErrorDestructurer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
77
// --- | --- | --- | --- | ---
88
// ErrorType | O | O | O | O
99
// ErrorCode | O | O | O | X
10-
// ErrorCodeId | O | O | O | O
10+
// NumericCode | O | O | O | O
1111
// ErrorCurrentValue | O | O | X | X
1212
// Message | O | O | O | X
1313
// Count | x | x | X | O
@@ -21,7 +21,7 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
2121
// "Error": {
2222
// "ErrorType": "ExpectedError", <- string 에러 타입
2323
// "ErrorCode": "<에러 코드>",
24-
// "ErrorCodeId": <에러 Id>
24+
// "NumericCode": <에러 Id>
2525
// "ErrorCurrentValue": "<현재 값>"
2626
// "Message": "<에러 메시지>",
2727
// },
@@ -33,7 +33,7 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
3333
// "Error": {
3434
// "ErrorType": "ExpectedError`1", <- <T> 에러 타입
3535
// "ErrorCode": "<에러 코드>",
36-
// "ErrorCodeId": <에러 Id>
36+
// "NumericCode": <에러 Id>
3737
// "ErrorCurrentValue": {
3838
// "X": 2025,
3939
// "Y": 2026,
@@ -49,7 +49,7 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
4949
// "Error": {
5050
// "ErrorType": "ExpectedError`2", <- <T1, T2> 에러 타입
5151
// "ErrorCode": "<에러 코드>",
52-
// "ErrorCodeId": <에러 Id>
52+
// "NumericCode": <에러 Id>
5353
// "ErrorCurrentValue1": {
5454
// "X": 2025,
5555
// "Y": 2026,
@@ -69,13 +69,13 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
6969
//"Properties": {
7070
// "Error": {
7171
// "ErrorType": "ManyErrors", <- 에러 타입
72-
// "ErrorCodeId": -2000000006, <- -2000000006: ManyErrors 고유 Id
72+
// "NumericCode": -2000000006, <- -2000000006: ManyErrors 고유 Id
7373
// "Count": 2, <- 에러 건수
7474
// "Errors": [
7575
// {
7676
// "ErrorType": "ExpectedError",
7777
// "ErrorCode": "<에러 코드>",
78-
// "ErrorCodeId": <에러 Id>,
78+
// "NumericCode": <에러 Id>,
7979
// "ErrorCurrentValue": {
8080
// "X": 2025,
8181
// "Y": 2026,
@@ -93,7 +93,7 @@ namespace Functorium.Adapters.Abstractions.Errors.DestructuringPolicies;
9393
//"Properties": {
9494
// "Error": {
9595
// "ErrorType": "ExceptionalError", <- 예외 타입
96-
// "ErrorCodeId": -2147352558, <- Exception의 HResult
96+
// "NumericCode": -2147352558, <- Exception의 HResult
9797
// "Message": "Attempted to divide by zero.", <- Exception의 Message
9898
// "ExceptionDetails": {
9999
// "TargetSite": "Int32 Divide(Int32, Int32)",

Src/Functorium/Abstractions/Errors/ErrorCodeFieldNames.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Functorium.Abstractions.Errors;
2+
3+
/// <summary>
4+
/// Serilog destructurer가 구조화 로그 출력에 사용하는 필드 이름 상수.
5+
/// </summary>
6+
/// <remarks>
7+
/// <para>
8+
/// 이 상수들은 로그 JSON/텍스트 출력에서 키로 쓰이며, 대시보드·알림 쿼리가
9+
/// 이 이름을 참조합니다. 상수 값을 변경하면 하위 관측성 소비자(Seq·Grafana·
10+
/// Elastic)의 쿼리도 함께 마이그레이션해야 합니다.
11+
/// </para>
12+
/// <para>
13+
/// <c>Kind</c>는 에러 레코드의 분류(<c>ExpectedError</c>·<c>ExceptionalError</c>·
14+
/// <c>ManyErrors</c>)를 담습니다. 이전 이름(<c>ErrorType</c>)은 <c>ErrorKind</c>
15+
/// 추상 record와 혼동되어 <c>Kind</c>로 단축·명확화되었습니다.
16+
/// </para>
17+
/// </remarks>
18+
internal static class ErrorLogFieldNames
19+
{
20+
public const string ErrorCode = nameof(ExpectedError.ErrorCode);
21+
public const string Message = nameof(ExpectedError.Message);
22+
public const string ErrorCurrentValue = nameof(ExpectedError.ErrorCurrentValue);
23+
public const string NumericCode = nameof(ExpectedError.NumericCode);
24+
25+
public const string Kind = nameof(Kind);
26+
public const string Count = nameof(Count);
27+
public const string Errors = nameof(Errors);
28+
public const string InnerError = nameof(InnerError);
29+
public const string ExceptionDetails = nameof(ExceptionDetails);
30+
31+
public const string UnknownErrorCode = "UNKNOWN.ERROR-CODE";
32+
public const string UnknownErrorMessage = "UNKNOWN.ERROR-MESSAGE";
33+
}

Src/Functorium/Abstractions/Errors/ExpectedError.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ internal record ExpectedError(
88
string ErrorCode,
99
string ErrorCurrentValue,
1010
string ErrorMessage,
11-
int ErrorCodeId = -1000,
11+
int NumericCode = -1000,
1212
Option<Error> Inner = default)
13-
: ExpectedErrorBase(ErrorCode, ErrorMessage, ErrorCodeId, Inner)
13+
: ExpectedErrorBase(ErrorCode, ErrorMessage, NumericCode, Inner)
1414
{
1515
[Pure]
1616
[DataMember]
@@ -23,9 +23,9 @@ internal record ExpectedError<T>(
2323
string ErrorCode,
2424
T ErrorCurrentValue,
2525
string ErrorMessage,
26-
int ErrorCodeId = -1000,
26+
int NumericCode = -1000,
2727
Option<Error> Inner = default)
28-
: ExpectedErrorBase(ErrorCode, ErrorMessage, ErrorCodeId, Inner)
28+
: ExpectedErrorBase(ErrorCode, ErrorMessage, NumericCode, Inner)
2929
where T : notnull
3030
{
3131
[Pure]
@@ -40,9 +40,9 @@ internal record ExpectedError<T1, T2>(
4040
T1 ErrorCurrentValue1,
4141
T2 ErrorCurrentValue2,
4242
string ErrorMessage,
43-
int ErrorCodeId = -1000,
43+
int NumericCode = -1000,
4444
Option<Error> Inner = default)
45-
: ExpectedErrorBase(ErrorCode, ErrorMessage, ErrorCodeId, Inner)
45+
: ExpectedErrorBase(ErrorCode, ErrorMessage, NumericCode, Inner)
4646
where T1 : notnull
4747
where T2 : notnull
4848
{
@@ -64,9 +64,9 @@ internal record ExpectedError<T1, T2, T3>(
6464
T2 ErrorCurrentValue2,
6565
T3 ErrorCurrentValue3,
6666
string ErrorMessage,
67-
int ErrorCodeId = -1000,
67+
int NumericCode = -1000,
6868
Option<Error> Inner = default)
69-
: ExpectedErrorBase(ErrorCode, ErrorMessage, ErrorCodeId, Inner)
69+
: ExpectedErrorBase(ErrorCode, ErrorMessage, NumericCode, Inner)
7070
where T1 : notnull
7171
where T2 : notnull
7272
where T3 : notnull

0 commit comments

Comments
 (0)