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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
