forked from Militereum/Militereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.pas
79 lines (65 loc) · 1.58 KB
/
error.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
unit error;
interface
uses
// web3;
web3,
// project
checks;
type
IMilitereumError = interface(IError)
['{535E852A-0D54-4523-A370-BE4576B38695}']
function FuncName: string;
function Comment : IResult<string>;
end;
function wrap(const inner: IError; const step: TStep): IMilitereumError;
implementation
uses
// Delphi
System.Rtti;
{ TMilitereumError }
type
TMilitereumError = class(TError, IMilitereumError)
private
FFuncName: string;
FComment : TComment;
public
constructor Create(const msg: string; const step: TStep);
function FuncName: string;
function Comment : IResult<string>;
end;
constructor TMilitereumError.Create(const msg: string; const step: TStep);
begin
inherited Create(msg);
const context = TRttiContext.Create;
try
const T = context.GetType(TObject(System.TMethod(step).Data).ClassType);
for var method in T.GetMethods do
if method.CodeAddress = System.TMethod(step).Code then
begin
FFuncName := method.Name;
FComment := method.GetAttribute<TComment>;
EXIT;
end;
finally
context.Free;
end;
end;
function TMilitereumError.FuncName: string;
begin
Result := FFuncName;
end;
function TMilitereumError.Comment: IResult<string>;
begin
if Assigned(FComment) then
Result := TResult<string>.Ok(FComment.Value)
else
Result := TResult<string>.Err('no comment');
end;
function wrap(const inner: IError; const step: TStep): IMilitereumError;
begin
if Assigned(inner) then
Result := TMilitereumError.Create(inner.Message, step)
else
Result := nil;
end;
end.