Skip to content

Commit 4a7572e

Browse files
committed
Remove ExecutedFunctionThrowException and replace with direct exception propagation in LPFCP.
1 parent 544f5f5 commit 4a7572e

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
`core` module:
33
- Made JSON library (`org.json`) an `api` dependency
44
- Disabled types auto-boxing when working with Java primitives
5+
- Remove `ExecutedFunctionThrowException` and replace with direct exception propagation in `LPFCP`.
56

67
`ktor` module:
78
- Updated Ktor to version `3.1.3`

core/src/main/java/eth/likespro/lpfcp/LPFCP.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ object LPFCP {
5757
*/
5858
class NoMatchingFunctionFoundException(msg: String) : RuntimeException(msg)
5959

60-
/**
61-
* Exception thrown when the invoked function throws an exception during execution.
62-
* @param e The original exception thrown by the function.
63-
*/
64-
class ExecutedFunctionThrowException(e: Throwable) : RuntimeException(e)
65-
6660

6761

6862
/*
@@ -102,7 +96,6 @@ object LPFCP {
10296
* @throws IncorrectFunctionNameException If the `functionName` key is missing or invalid.
10397
* @throws IncorrectFunctionArgsException If the `functionArgs` key is missing or invalid.
10498
* @throws NoMatchingFunctionFoundException If no matching function is found.
105-
* @throws ExecutedFunctionThrowException If the invoked function throws an exception.
10699
*/
107100
@OptIn(ExperimentalStdlibApi::class)
108101
fun processRequestUnsafely(request: JSONObject, processor: Any): Any? {
@@ -142,7 +135,7 @@ object LPFCP {
142135
return result
143136
} catch (e: InvocationTargetException) {
144137
// Handle exceptions thrown by the invoked function
145-
throw ExecutedFunctionThrowException(e.cause!!)
138+
throw e.cause!!
146139
} catch (_: IllegalArgumentException) {
147140
// Handle argument mismatch errors
148141
// Skip this function and continue searching for another one

core/src/test/java/eth/likespro/lpfcp/LPFCPTests.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.json.JSONObject
66
import org.junit.jupiter.api.Assertions.assertEquals
77
import org.junit.jupiter.api.Test
88
import org.junit.jupiter.api.assertThrows
9+
import java.lang.ArithmeticException
910

1011
class LPFCPTests {
1112
/*
@@ -165,14 +166,14 @@ class LPFCPTests {
165166
}
166167

167168
@Test
168-
fun processRequest_withFunctionThrowingException_returnsExecutedFunctionThrowException() {
169+
fun processRequest_withFunctionThrowingException_returnsIllegalStateException() {
169170
val processor = object {
170171
@LPFCP.ExposedFunction
171172
fun throwError(): Nothing = throw kotlin.IllegalStateException("Error occurred")
172173
}
173174
val request = JSONObject("""{"functionName": "throwError", "functionArgs": {}}""")
174175
val result = LPFCP.processRequest(request, processor)
175-
assertEquals(LPFCP.ExecutedFunctionThrowException::class.java, result.failure?.exceptionClass)
176+
assertEquals(IllegalStateException::class.java, result.failure?.exceptionClass)
176177
}
177178

178179

@@ -275,12 +276,12 @@ class LPFCPTests {
275276
assertEquals("45", result)
276277
}
277278

278-
@Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsExecutedFunctionThrowException() {
279+
@Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsArithmeticException() {
279280
val processor = LPFCP.getProcessor<Calculator> { request, _ ->
280281
LPFCP.processRequest(request, calculator).getOrThrow()
281282
}
282283
assertEquals(
283-
LPFCP.ExecutedFunctionThrowException::class.java,
284+
ArithmeticException::class.java,
284285
assertThrows<WrappedException.Exception> { processor.divide(5, 0) }.wrappedException.exceptionClass
285286
)
286287
}

ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTests.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
88
import org.junit.jupiter.api.BeforeAll
99
import org.junit.jupiter.api.Test
1010
import org.junit.jupiter.api.assertThrows
11+
import java.lang.ArithmeticException
1112
import java.net.URI
1213

1314
class KtorTests {
@@ -99,10 +100,10 @@ class KtorTests {
99100
assertEquals("45", response)
100101
}
101102

102-
@Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsExecutedFunctionThrowException() {
103+
@Test fun getProcessor_withLambda_proceedsRequest_withFunctionThrowingException_returnsArithmeticException() {
103104
val processor = LPFCP.getProcessor<Calculator>("http://localhost:8080/lpfcp")
104105
assertEquals(
105-
LPFCP.ExecutedFunctionThrowException::class.java,
106+
ArithmeticException::class.java,
106107
assertThrows<WrappedException.Exception> { processor.divide(5, 0) }.wrappedException.exceptionClass
107108
)
108109
}

0 commit comments

Comments
 (0)