This is an automated email from the ASF dual-hosted git repository.

aglinxinyuan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/texera.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b3af51c9b fix: replace bare Option.get in getPortId with descriptive 
IllegalStateException     (#4978)
6b3af51c9b is described below

commit 6b3af51c9b81b30ba014a751dfe0aa5d5aa7dd71
Author: Matthew B. <[email protected]>
AuthorDate: Thu May 7 14:28:04 2026 -0700

    fix: replace bare Option.get in getPortId with descriptive 
IllegalStateException     (#4978)
    
    ### What changes were proposed in this PR?
    AmberFIFOChannel.getPortId called this.portId.get on an
    Option[PortIdentity] that defaults to None. Calling getPortId before
    setPortId threw a bare NoSuchElementException with no message, giving
    callers no indication of which channel was misconfigured or what setup
    step was missed.
    Replaced .get with .getOrElse(throw new IllegalStateException(...)) so
    the exception identifies the channel and points the caller at the
    missing setPortId call.
    
    ### Any related issues, documentation, discussions?
    Closes: #4818
    
    
    ### How was this PR tested?
    Updated the existing AmberFIFOChannelSpec test that covered this path —
    it previously asserted NoSuchElementException and now asserts
    IllegalStateException with message content checks ("portId has not been
    set" and the channel ID string). All 13 specs pass.
    
    
    ### Was this PR authored or co-authored using generative AI tooling?
    Co-Authored with Claude Opus 4.7 in compliance with ASF
---
 .../engine/architecture/messaginglayer/AmberFIFOChannel.scala      | 6 +++++-
 .../engine/architecture/messaginglayer/AmberFIFOChannelSpec.scala  | 7 ++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannel.scala
 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannel.scala
index d81b4239ba..d1b5d7ab01 100644
--- 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannel.scala
+++ 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannel.scala
@@ -117,6 +117,10 @@ class AmberFIFOChannel(val channelId: ChannelIdentity) 
extends AmberLogging {
   }
 
   def getPortId: PortIdentity = {
-    this.portId.get
+    this.portId.getOrElse(
+      throw new IllegalStateException(
+        s"portId has not been set for channel $channelId; call setPortId 
before getPortId"
+      )
+    )
   }
 }
diff --git 
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannelSpec.scala
 
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannelSpec.scala
index 2109d22e32..5da17269d0 100644
--- 
a/amber/src/test/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannelSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/amber/engine/architecture/messaginglayer/AmberFIFOChannelSpec.scala
@@ -184,12 +184,13 @@ class AmberFIFOChannelSpec extends AnyFlatSpec {
   // PortId association
   // 
---------------------------------------------------------------------------
 
-  "AmberFIFOChannel.getPortId" should "throw when no portId has been set" in {
+  "AmberFIFOChannel.getPortId" should "throw IllegalStateException with a 
descriptive message when no portId has been set" in {
     val ch = new AmberFIFOChannel(cid)
-    // Option.get on None
-    assertThrows[NoSuchElementException] {
+    val ex = intercept[IllegalStateException] {
       ch.getPortId
     }
+    assert(ex.getMessage.contains("portId has not been set"))
+    assert(ex.getMessage.contains(cid.toString))
   }
 
   it should "return the most recently configured portId" in {

Reply via email to