File tree Expand file tree Collapse file tree
main/java/ai/openclaw/app/gateway
test/java/ai/openclaw/app/gateway Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package ai.openclaw.app.gateway
22
3+ private val invokeErrorCodePattern = Regex (" ^[A-Z][A-Z0-9_]*$" )
4+
35data class ParsedInvokeError (
46 val code : String ,
57 val message : String ,
@@ -24,7 +26,7 @@ fun parseInvokeErrorMessage(raw: String): ParsedInvokeError {
2426 if (parts.size == 2 ) {
2527 val code = parts[0 ].trim()
2628 val rest = parts[1 ].trim()
27- if (code.isNotEmpty() && code.all { it.isUpperCase() || it == ' _ ' } ) {
29+ if (invokeErrorCodePattern.matches( code) ) {
2830 return ParsedInvokeError (
2931 code = code,
3032 message = rest.ifEmpty { trimmed },
Original file line number Diff line number Diff line change @@ -15,12 +15,28 @@ class InvokeErrorParserTest {
1515 assertEquals(" CAMERA_PERMISSION_REQUIRED: grant Camera permission" , parsed.prefixedMessage)
1616 }
1717
18+ @Test
19+ fun parseInvokeErrorMessage_parsesNumericCodePrefix () {
20+ val parsed = parseInvokeErrorMessage(" A2UI_HOST_UNAVAILABLE: bundled A2UI host not reachable" )
21+ assertEquals(" A2UI_HOST_UNAVAILABLE" , parsed.code)
22+ assertEquals(" bundled A2UI host not reachable" , parsed.message)
23+ assertTrue(parsed.hadExplicitCode)
24+ }
25+
1826 @Test
1927 fun parseInvokeErrorMessage_rejectsNonCanonicalCodePrefix () {
20- val parsed = parseInvokeErrorMessage(" IllegalStateException: boom" )
21- assertEquals(" UNAVAILABLE" , parsed.code)
22- assertEquals(" IllegalStateException: boom" , parsed.message)
23- assertFalse(parsed.hadExplicitCode)
28+ listOf (
29+ " IllegalStateException: boom" ,
30+ " 2FAST: boom" ,
31+ " _PRIVATE: boom" ,
32+ " CAMERA-PERMISSION: boom" ,
33+ )
34+ .forEach { raw ->
35+ val parsed = parseInvokeErrorMessage(raw)
36+ assertEquals(" UNAVAILABLE" , parsed.code)
37+ assertEquals(raw, parsed.message)
38+ assertFalse(parsed.hadExplicitCode)
39+ }
2440 }
2541
2642 @Test
You can’t perform that action at this time.
0 commit comments