You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Modo-me (via GitHub)" <gi...@apache.org> on 2026/07/05 18:48:59 UTC
[PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Modo-me opened a new pull request, #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397
<!-- Thanks for sending a pull request!
-->
**What this PR does**:
在 dubbo-go-hessian2 中新增 GenericException 定义
**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes https://github.com/apache/dubbo-go/issues/3361
**Special notes for your reviewer**:
实现了 https://github.com/apache/dubbo-go/issues/3361 里的阶段1,在dubbo-go-hessian2 中新增 GenericException结构体以及相关方法,根据原dubbo-go 侧的 GenericException定义,保持新增内容与此前https://github.com/apache/dubbo-go/pull/3183 里引入的GenericException新增内容一致。对Java端兼容没有产生影响。
**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
NONE
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3526633136
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
Review Comment:
ok
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3526307989
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
+}
+
+func parseLegacyException(exStr string) *GenericException {
Review Comment:
[P1] 这个兼容分支会丢失旧字符串异常里的原始 Java 类名。当前 `Error()` 输出格式是 `java exception: <class> - <message>`,但这里仅去掉前缀后就固定把 `ExceptionClass` 写成 `java.lang.Exception`。也就是说,历史字符串异常一旦经过 `ToGenericException()`,类名信息就不可逆地丢失了。这里至少需要识别 `"<class> - <message>"` 这种已有格式并拆回两个字段。
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
Review Comment:
[P1] 这个新增文件当前没有通过 `gofmt`。我本地跑 `gofmt -l generic_exception.go` 会直接报出这个文件,原因就是这里拆成了两个 import block。按仓库 Go 规范应整理成单个 import block。
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
Review Comment:
[P1] 这个 PR 新增了 `GenericException` / `ToGenericException` 的核心行为,但没有配套单测覆盖 `DubboGenericException`、普通 `Throwabler`、以及 legacy string(尤其是 `java exception: <class> - <message>`)这三条分支。当前兼容逻辑已经涉及字符串解析和信息归一化,没有测试的话很容易在后续重构里悄悄回归。
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "tiltwind (via GitHub)" <gi...@apache.org>.
tiltwind commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4977539317
@Modo-me 问一下:
1. 这个新增的exception 和原来这两个是什么关系? 什么情况下会用这个新增的? java_exception/dubbo_generic_exception.go, java_exception/exception.go
2. 这个exception 需要序列化吗?是否需要补充序列号反序列化的 unit test ?
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3578175913
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
+}
Review Comment:
[P1] 当前 Head `f2818f07` 仍可复现 typed-nil 问题。WSL 探针结果:`(*GenericException)(nil)` 返回 `ok=true` 且结果为 nil;`(*DubboGenericException)(nil)` 在读取字段时 panic;nil `Throwabler` 在调用值接收者方法时 panic。请在所有指针/接口分支前统一检查 typed-nil,并补这三类回归测试,保证不会返回 `(nil, true)` 或崩溃。
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "tiltwind (via GitHub)" <gi...@apache.org>.
tiltwind commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4977577239
查看了一下 https://github.com/apache/dubbo-go/pull/3183 , GenericException 不参与序列化。
@Modo-me 建议代码中补充说明一下它的用途, 它和其他exception不一样, 其他exception都会注册并可能被序列化/反序列化处理。
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3526590551
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
Review Comment:
dubbo-go-hessian2仓库里的[contributing.md](https://github.com/apache/dubbo-go-hessian2/blob/master/contributing.md)要求这样拆开import block,是要求已经过时了吗,然后仓库内其他的文件也都是拆开的
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3578613076
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
+}
Review Comment:
已修复
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4968729159
增加了`ToGenericException()`里对所有分支的typed-nil检查,以及相应的回归测试
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3526013723
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
+}
Review Comment:
`ToGenericException` can panic if callers pass an interface holding a typed-nil pointer (e.g., `(*java_exception.DubboGenericException)(nil)` or a nil `Throwabler`). In those cases the type switch matches and the code dereferences/calls methods on `nil`. Consider treating typed-nil as "not convertible" (or otherwise returning a non-nil `*GenericException`) so the function never panics when it returns `ok=true`.
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
+}
+
+func parseLegacyException(exStr string) *GenericException {
+ const prefix = "java exception:"
+ msg := strings.TrimSpace(exStr)
+ if strings.HasPrefix(msg, prefix) {
+ msg = strings.TrimSpace(strings.TrimPrefix(msg, prefix))
+ }
+ return &GenericException{ExceptionClass: "java.lang.Exception", ExceptionMessage: msg}
+}
Review Comment:
`parseLegacyException` strips the `java exception:` prefix but never parses the "<class> - <message>" format produced by `GenericException.Error()`. That means passing an error string like `java exception: com.foo.Bar - boom` into `ToGenericException` loses the exception class. Consider parsing the delimiter when present and falling back to the legacy default only when the class/message cannot be extracted.
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
+ "strings"
+)
+
+import (
+ "github.com/apache/dubbo-go-hessian2/java_exception"
+)
+
+// GenericException keeps Java exception class and message.
+type GenericException struct {
+ ExceptionClass string
+ ExceptionMessage string
+}
+
+// Error returns a readable error string.
+func (e GenericException) Error() string {
+ if e.ExceptionClass == "" {
+ return e.ExceptionMessage
+ }
+ if e.ExceptionMessage == "" {
+ return e.ExceptionClass
+ }
+ return "java exception: " + e.ExceptionClass + " - " + e.ExceptionMessage
+}
+
+// ToGenericException converts decoded exception to GenericException when possible.
+func ToGenericException(expt any) (*GenericException, bool) {
+ switch v := expt.(type) {
+ case *GenericException:
+ return v, true
+ case GenericException:
+ return &v, true
+ case *java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.DubboGenericException:
+ return &GenericException{ExceptionClass: v.ExceptionClass, ExceptionMessage: v.ExceptionMessage}, true
+ case java_exception.Throwabler:
+ return &GenericException{ExceptionClass: v.JavaClassName(), ExceptionMessage: v.Error()}, true
+ case string:
+ return parseLegacyException(v), true
+ }
+ return nil, false
Review Comment:
This change introduces a new exported conversion helper with several non-trivial branches (typed values, pointers, `Throwabler`, legacy string parsing). The repository has extensive decoder/exception tests already, but there are no tests covering `ToGenericException`/`parseLegacyException` behavior (including nil-safety and parsing). Adding a small `generic_exception_test.go` would help prevent regressions.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#discussion_r3526628289
##########
generic_exception.go:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 hessian
+
+import (
Review Comment:
忽略这个comment
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "wongoo (via GitHub)" <gi...@apache.org>.
wongoo merged PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4977600908
这个新增的exception来自于https://github.com/apache/dubbo-go/pull/3183 而并非此次pr新增,在dubbo-go源码的protocol/dubbo/hessian2/hessian_response.go下。而这个pr旨在把这个exception的定义从dubbo-go迁移到dubbo-go-hessian2(根据https://github.com/apache/dubbo-go/issues/3361),同时补全了对应的单测
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4917098109
已修复CI错误
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] Add: GenericException struct and ToGenericException converter [dubbo-go-hessian2]
Posted by "Modo-me (via GitHub)" <gi...@apache.org>.
Modo-me commented on PR #397:
URL: https://github.com/apache/dubbo-go-hessian2/pull/397#issuecomment-4889961785
在`parseLegacyException()`添加了保留`java exception: <class> - <message>`格式下的类名的逻辑,以及添加对`parseLegacyException()` `ToGenericException()`和`Error()`的配套单测
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org