@@ -15,6 +15,16 @@ namespace NMiniKQL {
15
15
16
16
namespace {
17
17
18
+ constexpr size_t TypeDiffLimit = 1000 ;
19
+
20
+ TString TruncateTypeDiff (const TString& s) {
21
+ if (s.size () < TypeDiffLimit) {
22
+ return s;
23
+ }
24
+
25
+ return s.substr (0 ,TypeDiffLimit) + " ..." ;
26
+ }
27
+
18
28
template <class TValidatePolicy , class TValidateMode >
19
29
class TSimpleUdfWrapper : public TMutableComputationNode <TSimpleUdfWrapper<TValidatePolicy,TValidateMode>> {
20
30
using TBaseComputation = TMutableComputationNode<TSimpleUdfWrapper<TValidatePolicy,TValidateMode>>;
@@ -43,8 +53,15 @@ using TBaseComputation = TMutableComputationNode<TSimpleUdfWrapper<TValidatePoli
43
53
ctx.TypeEnv , ctx.TypeInfoHelper , ctx.CountersProvider , FunctionName, UserType->IsVoid () ? nullptr : UserType,
44
54
TypeConfig, flags, Pos, ctx.SecureParamsProvider , &funcInfo);
45
55
46
- MKQL_ENSURE (status.IsOk (), status.GetError ());
47
- MKQL_ENSURE (funcInfo.Implementation , " UDF implementation is not set for function " << FunctionName);
56
+ if (!status.IsOk ()) {
57
+ UdfTerminate ((TStringBuilder () << Pos << " Failed to find UDF function " << FunctionName << " , reason: "
58
+ << status.GetError ()).c_str ());
59
+ }
60
+
61
+ if (!funcInfo.Implementation ) {
62
+ UdfTerminate ((TStringBuilder () << Pos << " UDF implementation is not set for function " << FunctionName).c_str ());
63
+ }
64
+
48
65
NUdf::TUnboxedValue udf (NUdf::TUnboxedValuePod (funcInfo.Implementation .Release ()));
49
66
TValidate<TValidatePolicy,TValidateMode>::WrapCallable (CallableType, udf, TStringBuilder () << " FunctionWithConfig<" << FunctionName << " >" );
50
67
return udf.Release ();
@@ -190,13 +207,19 @@ using TBaseComputation = TMutableCodegeneratorPtrNode<TUdfWrapper<TValidatePolic
190
207
ctx.TypeEnv , ctx.TypeInfoHelper , ctx.CountersProvider , FunctionName, UserType->IsVoid () ? nullptr : UserType,
191
208
TypeConfig, flags, Pos, ctx.SecureParamsProvider , &funcInfo);
192
209
193
- MKQL_ENSURE (status.IsOk (), status.GetError ());
194
- MKQL_ENSURE (funcInfo.Implementation , " UDF implementation is not set for function " << FunctionName);
210
+ if (!status.IsOk ()) {
211
+ UdfTerminate ((TStringBuilder () << Pos << " Failed to find UDF function " << FunctionName << " , reason: "
212
+ << status.GetError ()).c_str ());
213
+ }
214
+
215
+ if (!funcInfo.Implementation ) {
216
+ UdfTerminate ((TStringBuilder () << Pos << " UDF implementation is not set for function " << FunctionName).c_str ());
217
+ }
218
+
195
219
udf = NUdf::TUnboxedValuePod (funcInfo.Implementation .Release ());
196
220
}
197
221
198
222
void Wrap (NUdf::TUnboxedValue& callable) const {
199
- MKQL_ENSURE (bool (callable), " Returned empty value in function: " << FunctionName);
200
223
TValidate<TValidatePolicy,TValidateMode>::WrapCallable (CallableType, callable, TStringBuilder () << " FunctionWithConfig<" << FunctionName << " >" );
201
224
}
202
225
@@ -270,16 +293,27 @@ IComputationNode* WrapUdf(TCallable& callable, const TComputationNodeFactoryCont
270
293
ctx.Env , ctx.TypeInfoHelper , ctx.CountersProvider , funcName, userType->IsVoid () ? nullptr : userType,
271
294
typeConfig, flags, pos, ctx.SecureParamsProvider , &funcInfo);
272
295
273
- MKQL_ENSURE (status.IsOk (), status.GetError ());
274
- MKQL_ENSURE (funcInfo.FunctionType ->IsConvertableTo (*callable.GetType ()->GetReturnType (), true ),
275
- " Function '" << funcName << " ' type mismatch, expected return type: " << PrintNode (callable.GetType ()->GetReturnType (), true ) <<
276
- " , actual:" << PrintNode (funcInfo.FunctionType , true ));
277
- MKQL_ENSURE (funcInfo.Implementation , " UDF implementation is not set for function " << funcName);
296
+ if (!status.IsOk ()) {
297
+ UdfTerminate ((TStringBuilder () << pos << " Failed to find UDF function " << funcName << " , reason: "
298
+ << status.GetError ()).c_str ());
299
+ }
300
+
301
+ if (!funcInfo.FunctionType ->IsConvertableTo (*callable.GetType ()->GetReturnType (), true )) {
302
+ TString diff = TStringBuilder () << " type mismatch, expected return type: " << PrintNode (callable.GetType ()->GetReturnType (), true ) <<
303
+ " , actual:" << PrintNode (funcInfo.FunctionType , true );
304
+ UdfTerminate ((TStringBuilder () << pos << " UDF Function '" << funcName << " ' " << TruncateTypeDiff (diff)).c_str ());
305
+ }
306
+
307
+ if (!funcInfo.Implementation ) {
308
+ UdfTerminate ((TStringBuilder () << pos << " UDF implementation is not set for function " << funcName).c_str ());
309
+ }
278
310
279
311
const auto runConfigType = funcInfo.RunConfigType ;
280
- const bool typesMatch = runConfigType->IsSameType (*runCfgNode.GetStaticType ());
281
- MKQL_ENSURE (typesMatch, " RunConfig '" << funcName << " ' type mismatch, expected: " << PrintNode (runCfgNode.GetStaticType (), true ) <<
282
- " , actual: " << PrintNode (runConfigType, true ));
312
+ if (!runConfigType->IsSameType (*runCfgNode.GetStaticType ())) {
313
+ TString diff = TStringBuilder () << " run config type mismatch, expected: " << PrintNode (runCfgNode.GetStaticType (), true ) <<
314
+ " , actual:" << PrintNode (runConfigType, true );
315
+ UdfTerminate ((TStringBuilder () << pos << " UDF Function '" << funcName << " ' " << TruncateTypeDiff (diff)).c_str ());
316
+ }
283
317
284
318
if (runConfigType->IsVoid ()) {
285
319
if (ctx.ValidateMode == NUdf::EValidateMode::None && funcInfo.ModuleIR && funcInfo.IRFunctionName ) {
@@ -320,10 +354,20 @@ IComputationNode* WrapScriptUdf(TCallable& callable, const TComputationNodeFacto
320
354
const auto status = ctx.FunctionRegistry .FindFunctionTypeInfo (
321
355
ctx.Env , ctx.TypeInfoHelper , ctx.CountersProvider , funcName, userType,
322
356
typeConfig, flags, pos, ctx.SecureParamsProvider , &funcInfo);
323
- MKQL_ENSURE (status.IsOk (), status.GetError ());
324
- MKQL_ENSURE (funcInfo.Implementation , " UDF implementation is not set" );
325
357
326
- MKQL_ENSURE (!funcInfo.FunctionType , " Function type info is exist for same kind script, it's better use it" );
358
+ if (!status.IsOk ()) {
359
+ UdfTerminate ((TStringBuilder () << pos << " Failed to find UDF function " << funcName << " , reason: "
360
+ << status.GetError ()).c_str ());
361
+ }
362
+
363
+ if (!funcInfo.Implementation ) {
364
+ UdfTerminate ((TStringBuilder () << pos << " UDF implementation is not set for function " << funcName).c_str ());
365
+ }
366
+
367
+ if (funcInfo.FunctionType ) {
368
+ UdfTerminate ((TStringBuilder () << pos << " UDF function type exists for function " << funcName).c_str ());
369
+ }
370
+
327
371
const auto callableType = callable.GetType ();
328
372
MKQL_ENSURE (callableType->GetKind () == TType::EKind::Callable, " Expected callable type in callable type info" );
329
373
const auto callableResultType = callableType->GetReturnType ();
0 commit comments