@@ -103,13 +103,28 @@ func (p *FuncProvider) Invoke(args []reflect.Value) (results []reflect.Value, er
103
103
WithDetail ("actual" , len (args ))
104
104
}
105
105
106
+ // 收集入参信息用于错误记录
107
+ argTypes := make ([]string , len (args ))
108
+ argValues := make ([]interface {}, len (args ))
109
+ for i , arg := range args {
110
+ argTypes [i ] = arg .Type ().String ()
111
+ if arg .IsValid () && arg .CanInterface () {
112
+ argValues [i ] = arg .Interface ()
113
+ } else {
114
+ argValues [i ] = "<invalid_or_unexportable>"
115
+ }
116
+ }
117
+
106
118
defer func () {
107
119
if r := recover (); r != nil {
108
120
// 记录调用栈信息
109
121
fnStack := stack .CallerWithFunc (p .fn )
110
122
logger .Error ().
111
123
Str ("provider" , fnStack .String ()).
112
124
Interface ("panic" , r ).
125
+ Strs ("input_types" , argTypes ).
126
+ Interface ("input_values" , argValues ).
127
+ Str ("expected_output_type" , p .outputType .String ()).
113
128
Msg ("provider function panicked" )
114
129
115
130
// 将 panic 转换为错误
@@ -122,7 +137,10 @@ func (p *FuncProvider) Invoke(args []reflect.Value) (results []reflect.Value, er
122
137
err = WrapError (panicErr , ErrorTypeInvocation , "provider function panicked" ).
123
138
WithDetail ("provider_type" , p .outputType .String ()).
124
139
WithDetail ("panic_value" , r ).
125
- WithDetail ("provider_location" , fnStack .String ())
140
+ WithDetail ("provider_location" , fnStack .String ()).
141
+ WithDetail ("input_types" , argTypes ).
142
+ WithDetail ("input_values" , argValues ).
143
+ WithDetail ("expected_output_type" , p .outputType .String ())
126
144
}
127
145
}()
128
146
@@ -141,9 +159,23 @@ func (p *FuncProvider) Invoke(args []reflect.Value) (results []reflect.Value, er
141
159
errorValue := results [1 ]
142
160
if ! errorValue .IsNil () {
143
161
// 提取 error 并返回
144
- if err , ok := errorValue .Interface ().(error ); ok {
145
- return nil , WrapError (err , ErrorTypeProvider , "provider function returned error" ).
146
- WithDetail ("provider_type" , p .outputType .String ())
162
+ if providerErr , ok := errorValue .Interface ().(error ); ok {
163
+ // 记录 provider 返回 error 的详细信息
164
+ fnStack := stack .CallerWithFunc (p .fn )
165
+ logger .Error ().
166
+ Str ("provider" , fnStack .String ()).
167
+ Err (providerErr ).
168
+ Strs ("input_types" , argTypes ).
169
+ Interface ("input_values" , argValues ).
170
+ Str ("expected_output_type" , p .outputType .String ()).
171
+ Msg ("provider function returned error" )
172
+
173
+ return nil , WrapError (providerErr , ErrorTypeProvider , "provider function returned error" ).
174
+ WithDetail ("provider_type" , p .outputType .String ()).
175
+ WithDetail ("provider_location" , fnStack .String ()).
176
+ WithDetail ("input_types" , argTypes ).
177
+ WithDetail ("input_values" , argValues ).
178
+ WithDetail ("expected_output_type" , p .outputType .String ())
147
179
}
148
180
}
149
181
// 如果有 error 返回值但为 nil,只返回第一个值
0 commit comments