From a967f620c46021f6f048443e966c96895b41a277 Mon Sep 17 00:00:00 2001 From: wuyangfan Date: Tue, 9 Jun 2026 12:55:26 +0800 Subject: [PATCH 1/3] fix(java_exception): populate dubbo generic exception message --- java_exception/dubbo_generic_exception.go | 21 ++++- .../dubbo_generic_exception_test.go | 79 +++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 java_exception/dubbo_generic_exception_test.go diff --git a/java_exception/dubbo_generic_exception.go b/java_exception/dubbo_generic_exception.go index 4acde47d..e482233c 100644 --- a/java_exception/dubbo_generic_exception.go +++ b/java_exception/dubbo_generic_exception.go @@ -30,12 +30,29 @@ type DubboGenericException struct { // NewDubboGenericException is the constructor func NewDubboGenericException(exceptionClass, exceptionMessage string) *DubboGenericException { - return &DubboGenericException{ExceptionClass: exceptionClass, ExceptionMessage: exceptionMessage} + return &DubboGenericException{ + DetailMessage: formatDubboGenericExceptionMessage(exceptionClass, exceptionMessage), + ExceptionClass: exceptionClass, + ExceptionMessage: exceptionMessage, + } } // Error output error message func (e DubboGenericException) Error() string { - return e.DetailMessage + if e.DetailMessage != "" { + return e.DetailMessage + } + return formatDubboGenericExceptionMessage(e.ExceptionClass, e.ExceptionMessage) +} + +func formatDubboGenericExceptionMessage(exceptionClass, exceptionMessage string) string { + if exceptionClass == "" { + return exceptionMessage + } + if exceptionMessage == "" { + return exceptionClass + } + return "java exception: " + exceptionClass + " - " + exceptionMessage } // JavaClassName java fully qualified path diff --git a/java_exception/dubbo_generic_exception_test.go b/java_exception/dubbo_generic_exception_test.go new file mode 100644 index 00000000..67c55098 --- /dev/null +++ b/java_exception/dubbo_generic_exception_test.go @@ -0,0 +1,79 @@ +/* + * 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 java_exception + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewDubboGenericExceptionErrorMessage(t *testing.T) { + tests := []struct { + name string + exceptionClass string + exceptionMessage string + wantError string + }{ + { + name: "class and message", + exceptionClass: "com.example.UserNotFoundException", + exceptionMessage: "user not found", + wantError: "java exception: com.example.UserNotFoundException - user not found", + }, + { + name: "message only", + exceptionMessage: "user not found", + wantError: "user not found", + }, + { + name: "class only", + exceptionClass: "com.example.UserNotFoundException", + wantError: "com.example.UserNotFoundException", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + exception := NewDubboGenericException(test.exceptionClass, test.exceptionMessage) + assert.Equal(t, test.exceptionClass, exception.ExceptionClass) + assert.Equal(t, test.exceptionMessage, exception.ExceptionMessage) + assert.Equal(t, test.wantError, exception.DetailMessage) + assert.Equal(t, test.wantError, exception.Error()) + }) + } +} + +func TestDubboGenericExceptionErrorFallback(t *testing.T) { + exception := DubboGenericException{ + ExceptionClass: "com.example.UserNotFoundException", + ExceptionMessage: "user not found", + } + + assert.Equal(t, "java exception: com.example.UserNotFoundException - user not found", exception.Error()) +} + +func TestDubboGenericExceptionErrorPrefersDetailMessage(t *testing.T) { + exception := DubboGenericException{ + DetailMessage: "decoded detail", + ExceptionClass: "com.example.UserNotFoundException", + ExceptionMessage: "user not found", + } + + assert.Equal(t, "decoded detail", exception.Error()) +} From 47eb125ff42d2a4a4ecf6a50793305c7a3edeb12 Mon Sep 17 00:00:00 2001 From: wuyangfan Date: Wed, 10 Jun 2026 09:44:12 +0800 Subject: [PATCH 2/3] fix(java_exception): initialize generic exception stack trace --- java_exception/dubbo_generic_exception.go | 1 + java_exception/dubbo_generic_exception_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/java_exception/dubbo_generic_exception.go b/java_exception/dubbo_generic_exception.go index e482233c..3f5229b3 100644 --- a/java_exception/dubbo_generic_exception.go +++ b/java_exception/dubbo_generic_exception.go @@ -32,6 +32,7 @@ type DubboGenericException struct { func NewDubboGenericException(exceptionClass, exceptionMessage string) *DubboGenericException { return &DubboGenericException{ DetailMessage: formatDubboGenericExceptionMessage(exceptionClass, exceptionMessage), + StackTrace: []StackTraceElement{}, ExceptionClass: exceptionClass, ExceptionMessage: exceptionMessage, } diff --git a/java_exception/dubbo_generic_exception_test.go b/java_exception/dubbo_generic_exception_test.go index 67c55098..2136eddd 100644 --- a/java_exception/dubbo_generic_exception_test.go +++ b/java_exception/dubbo_generic_exception_test.go @@ -54,6 +54,8 @@ func TestNewDubboGenericExceptionErrorMessage(t *testing.T) { assert.Equal(t, test.exceptionClass, exception.ExceptionClass) assert.Equal(t, test.exceptionMessage, exception.ExceptionMessage) assert.Equal(t, test.wantError, exception.DetailMessage) + assert.NotNil(t, exception.StackTrace) + assert.Empty(t, exception.StackTrace) assert.Equal(t, test.wantError, exception.Error()) }) } From 3114c3f318e2090bf8b5cde745b6533cc8ec15cd Mon Sep 17 00:00:00 2001 From: wuyangfan Date: Mon, 15 Jun 2026 11:28:47 +0800 Subject: [PATCH 3/3] test(java_exception): format generic exception test imports --- java_exception/dubbo_generic_exception_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java_exception/dubbo_generic_exception_test.go b/java_exception/dubbo_generic_exception_test.go index 2136eddd..549ca713 100644 --- a/java_exception/dubbo_generic_exception_test.go +++ b/java_exception/dubbo_generic_exception_test.go @@ -19,7 +19,9 @@ package java_exception import ( "testing" +) +import ( "github.com/stretchr/testify/assert" )