paascloud/paascloud-master · error · IllegalArgumentException

钉钉机器人消息类型错误

Error message

钉钉机器人消息类型错误

What it means

A plain IllegalArgumentException ('钉钉机器人消息类型错误') thrown by DingtalkFeignClient.checkChatReBotMsg when the message object passed to sendChatRobotMsg has a msgtype that is not one of the supported Dingtalk robot message types handled by the validation branches (text, link, markdown, actionCard, feedCard, etc.). It is a programmer-error guard against unsupported/misspelled message types.

Solutions

  1. Set the message type to an exact supported value (e.g. "text", "link", "markdown", "actionCard", "feedCard") before calling sendChatRobotMsg.
  2. Log/inspect the msgtype actually sent; check case and whitespace.
  3. If a genuinely new Dingtalk type is needed, extend checkChatReBotMsg with a validation branch for it.
  4. Use an enum or constants class for Dingtalk message types instead of raw strings to prevent typos.
  5. Validate the type client-side before constructing the message.

Example fix

// before: free-form string type
DingtalkMessage msg = new DingtalkMessage();
msg.setMsgtype("Text"); // IllegalArgumentException
// after: use the exact supported value / constant
DingtalkMessage msg = new DingtalkMessage();
msg.setMsgtype(DingtalkConstants.MSG_TYPE_TEXT); // "text"
dingtalkFeignClient.sendChatRobotMsg(msg);
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> SUPPORTED_TYPES = Set.of("text","link","markdown","actionCard","feedCard");
if (msg.getMsgtype() == null || !SUPPORTED_TYPES.contains(msg.getMsgtype())) {
    throw new IllegalArgumentException("Unsupported Dingtalk msgtype: " + msg.getMsgtype());
}

Type guard

boolean isSupportedDingtalkType(DingtalkMessage m) {
    return m != null && m.getMsgtype() != null && SUPPORTED_TYPES.contains(m.getMsgtype().trim());
}

Try / catch

try {
    dingtalkFeignClient.sendChatRobotMsg(msg);
} catch (IllegalArgumentException e) {
    log.error("Dingtalk msg rejected: {}", e.getMessage());
    throw new BadRequestException("Unsupported Dingtalk message type");
}

Prevention

When it happens

Trigger: Calling sendChatRobotMsg with a DingtalkMessage whose type field is null, empty, misspelled (e.g. "text " with trailing space or "Text" wrong case), or an unsupported type not covered by checkChatReBotMsg's if/else chain.

Common situations: Copy-pasting a message builder from another codebase with a different type string; adding a new Dingtalk message type upstream without extending the client's validation; forgetting to set the type field entirely.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/63d399b24eb80f6f. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/web/rpc/DingtalkFeignClient.java:127

		} else if (RobotMsgTypeEnum.TEXT.getName().equals(msgType)) {
			TextDto text = chatRobotMsgDto.getText();
			AtDto at = chatRobotMsgDto.getAt();
			String content = text.getContent();

			Preconditions.checkArgument(PublicUtil.isNotEmpty(text), "text类型消息体空");
			Preconditions.checkArgument(PublicUtil.isNotEmpty(content), "text类型消息体内容为空");

			if (PublicUtil.isNotEmpty(at)) {
				String[] atMobiles = at.getAtMobiles();
				if (PublicUtil.isNotEmpty(atMobiles)) {
					for (String atMobile : atMobiles) {
						Preconditions.checkArgument(ValidateUtil.isMobileNumber(atMobile), "手机号码:" + atMobile + "格式错误");
					}
				}
			}

		} else {
			throw new IllegalArgumentException("钉钉机器人消息类型错误");
		}
	}
}

View on GitHub (pinned to 781281a950)