kunwp1 commented on code in PR #9215:
URL: https://github.com/apache/texera/pull/9215#discussion_r4690924295
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/PythonOperatorDescriptor.scala:
##########
@@ -26,7 +26,9 @@ import org.apache.texera.amber.core.workflow.{PhysicalOp,
PortIdentity, SchemaPr
trait PythonOperatorDescriptor extends LogicalOp {
private def generatePythonCodeForRaisingException(ex: Throwable): String = {
- s"#EXCEPTION DURING CODE GENERATION: ${ex.getMessage}"
+ // An exception with no message or an empty one is reported by its type
instead of "null".
+ val message =
Option(ex.getMessage).filter(_.nonEmpty).getOrElse(ex.toString)
Review Comment:
**Nit.** For an empty message, `ex.toString` gives
`java.lang.RuntimeException: `, so after the compiler's `trim` the reader sees
"Operator is not configured properly: java.lang.RuntimeException:" with a
dangling colon. Thus, `ex.getClass.getName` would report the type alone, as the
comment above describes, for both the null and the empty case.
##########
common/workflow-compiler/src/main/scala/org/apache/texera/common/compiler/WorkflowCompiler.scala:
##########
@@ -307,7 +307,9 @@ class WorkflowCompiler(
// **Check for Python-based operator errors during code
generation**
if (physicalOp.isPythonBased) {
val code = physicalOp.getCode
- val exceptionPattern = """#EXCEPTION DURING CODE
GENERATION:\s*(.*)""".r
+ // The marker is the whole code of a failed generation, so it
is only looked for
+ // at the very start; `(?s)` lets the captured message span
several lines.
+ val exceptionPattern = """(?s)^#EXCEPTION DURING CODE
GENERATION:\s*(.*)""".r
Review Comment:
**Optional.** The anchor is right, but it now depends on
`generatePythonCodeForRaisingException` writing the marker first, and the two
sides of this protocol live in different modules as two copies of one literal.
One way to make the contract explicit is to define the marker once on
`PythonOperatorDescriptor` and check it with `startsWith`, which also replaces
the regex:
```scala
object PythonOperatorDescriptor {
/** The whole code of a failed generation starts with this; the compiler
reports what follows. */
val CodeGenerationFailureMarker = "#EXCEPTION DURING CODE GENERATION:"
}
```
```scala
val marker =
PythonOperatorDescriptor.CodeGenerationFailureMarker
if (code.startsWith(marker)) {
val errorMessage = code.drop(marker.length).trim
```
Notice that `trim` already covers the `\s*`, and the message keeps every
line, as with `(?s)`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]