Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The wrong log type is used for log printing during error handling #670

Open
LJiangTao opened this issue Jul 22, 2024 · 0 comments
Open

The wrong log type is used for log printing during error handling #670

LJiangTao opened this issue Jul 22, 2024 · 0 comments

Comments

@LJiangTao
Copy link

LJiangTao commented Jul 22, 2024

environment

<dependency>
      <groupId>org.apache.rocketmq</groupId>
      <artifactId>rocketmq-spring-boot-starter</artifactId>
      <version>2.3.0</version>
</dependency>

current latest version also has issue.

describe

using wrong log type in try-catch exception handle.

in org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer#doConvertMessage method used log.info instead of log.error in exception handling.

    private Object doConvertMessage(MessageExt messageExt) {
        if (Objects.equals(messageType, MessageExt.class) || Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
            return messageExt;
        } else {
            String str = new String(messageExt.getBody(), Charset.forName(charset));
            if (Objects.equals(messageType, String.class)) {
                return str;
            } else {
                // If msgType not string, use objectMapper change it.
                try {
                   // ignored
                } catch (Exception e) {

                    // here it is 👇
                    log.info("convert failed. str:{}, msgType:{}", str, messageType);
                    throw new RuntimeException("cannot convert message to " + messageType, e);
                }
            }
        }
    }

log.info should print normal log, it shoud be using log.error instead of log.info

how to fix

    private Object doConvertMessage(MessageExt messageExt) {
        if (Objects.equals(messageType, MessageExt.class) || Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
            return messageExt;
        } else {
            String str = new String(messageExt.getBody(), Charset.forName(charset));
            if (Objects.equals(messageType, String.class)) {
                return str;
            } else {
                // If msgType not string, use objectMapper change it.
                try {
                   // ignored
                } catch (Exception e) {

                    // change like this
                    log.error("convert failed. str:{}, msgType:{},\n convert error msg: {}.", str, messageType, e.getMessage());
                    throw new RuntimeException("cannot convert message to " + messageType, e);
                }
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant