You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/10/26 00:27:47 UTC

[GitHub] [incubator-daffodil] bsloane1650 commented on a change in pull request #279: WIP: User Defined Functions feature

bsloane1650 commented on a change in pull request #279: WIP: User Defined Functions feature
URL: https://github.com/apache/incubator-daffodil/pull/279#discussion_r338344414
 
 

 ##########
 File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/UserDefinedFunctionBase.scala
 ##########
 @@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.dpath
+
+import org.apache.daffodil.udf.UserDefinedFunction
+import org.apache.daffodil.udf.UserDefinedFunctionService.UserDefinedFunctionMethod
+import java.lang.reflect.Method
+import java.lang.reflect.InvocationTargetException
+import org.apache.daffodil.udf.exceptions.UserDefinedFunctionFatalException
+import org.apache.daffodil.udf.exceptions.UserDefinedFunctionProcessingError
+import org.apache.daffodil.processors.ProcessingError
+import org.apache.daffodil.util.Maybe
+import org.apache.daffodil.exceptions.SchemaFileLocation
+import org.apache.daffodil.api.DataLocation
+import org.apache.daffodil.exceptions.Abort
+
+/**
+ * User Defined Function Exception class to wrap processing errors from the UDF
+ * into Daffodil Processing Errors
+ */
+case class UserDefinedFunctionProcessingErrorException(
+  errorInfo: String,
+  schemaContext: Maybe[SchemaFileLocation],
+  dataContext: Maybe[DataLocation],
+  errorCause: Maybe[Throwable],
+  errorStr: Maybe[String])
+  extends ProcessingError(errorInfo, schemaContext, dataContext, errorCause, errorStr)
+
+/**
+ * User Defined Function Exception class to wrap fatal errors from the UDF
+ * into Daffodil Aborts
+ */
+case class UserDefinedFunctionFatalErrorException(description: String = "", cause: Throwable, classOfInterest: String = "")
+  extends Abort(description ++ cause.getMessage) {
+
+  if (classOfInterest.nonEmpty) {
+    val curStackTrace = cause.getStackTrace
+    val indexLastUdfEntry = curStackTrace.lastIndexWhere(_.getClassName == classOfInterest)
+    val finalStackTrace = if (indexLastUdfEntry >= 0) curStackTrace.slice(0, indexLastUdfEntry + 1) else curStackTrace
+    this.setStackTrace(finalStackTrace)
+  }
 
 Review comment:
   This block probably deserves a comment

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services