fix: log the payload that is actually sent to DingTalk - #403
Merged
Conversation
`send()` reused its local `message` variable for the user's raw template when raw notification mode was added, but the "发送的消息详情" log line kept pointing at it. A built-in notification therefore logs literally "发送的消息详情,null", and a raw notification logs the template before variable expansion rather than the payload. Only one of the two call sites that had to move was caught at the time: the compiler rejected a String for `send(String, MessageModel)`, while `Utils.toJson(Object)` took it silently. Renaming the local to `rawMessage` stops the two from colliding again. The line only reaches the build log when the global verbose setting is on, i.e. exactly when someone is diagnosing a problem. The preceding "当前机器人信息" line already logs the notifier configuration including the raw template, so pointing this one at the payload loses nothing. Signed-off-by: BobDu <i@bobdu.cc>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
The
发送的消息详情(message details) line of the build log is the only place a user can see what the plugin actually posted to DingTalk. It has been logging the wrong object since the raw notification mode was added inc66a0df(2023-03).Before that commit, the local variable
messagewas theMessageModel, and the log line was correct.c66a0dfneeded a variable for the user's custom template and reused the same name for it, renaming the model tomsgModel. Two call sites had to follow, and only one of them did:send(String, MessageModel)rejected aString, so the compiler forced that one.Utils.toJson(Object)accepted it, so the log line kept compiling with entirely different meaning. The result:发送的消息详情,null, because the template field is unset when the built-in message is used;Every
DingTalkUtils.logcall is gated on the global verbose setting, so this line only reaches the build log once someone turns detailed logging on — which is exactly when they are trying to diagnose a delivery problem and getnullinstead.Nothing is lost by pointing it at the payload: the preceding
当前机器人信息line already logs the notifier configuration, raw template included.The local variable is renamed to
rawMessagein the same change. That is what removes the trap rather than just its symptom: there is no longer amessagein this scope for a future rename to collide with.Testing done
mvn clean verifypasses: 58 tests, plus spotless, access-modifier-checker, the enforcer import rules and spotbugs (0 findings).DingTalkRunListenerLogTestruns a real build throughJenkinsRuleagainst a robot pointing at a closed port, then asserts on the build log — one case for the built-in message, one for a raw template. Both assert the log carries the expanded payload, which is what distinguishes it from the configuration line above it.Both cases were checked by mutation: restoring
Utils.toJson(message)makes them fail with[钉钉插件]发送的消息详情,nullin the captured log, so they reproduce the reported behaviour rather than merely exercising the line.Submitter checklist