paascloud/paascloud-master · error · OmcBizException

OMC10031001

OMC10031001

Error message

OMC10031001

What it means

OMC10031001 means '购物车为空' (cart is empty, userId=%s). createOrderDoc loads the user's checked cart items via omcCartMapper.selectCheckedCartByUserId and throws when the list is empty (or when the computed order-detail list comes back empty), because an order cannot be created without any cart items.

Solutions

  1. Before checkout, verify the user has checked cart items (selectCheckedCartByUserId) and redirect to the cart page with a message if empty.
  2. Catch OmcBizException code 10031001 and return a friendly 'your cart is empty' response instead of a 500.
  3. Ensure the client sends the checked flags correctly when adding/updating cart items so selectCheckedCartByUserId returns them.
  4. Disable the checkout button server-validated-side when the checked cart is empty to prevent duplicate/stale submissions.

Example fix

// before
OrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);
// after
List<OmcCart> checked = omcCartMapper.selectCheckedCartByUserId(userId);
if (CollectionUtils.isEmpty(checked)) {
    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);
}
OrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);
Defensive patterns

Strategy: validation

Validate before calling

// Java, before invoking checkout
List<OmcCart> checked = omcCartMapper.selectCheckedCartByUserId(userId);
if (checked == null || checked.isEmpty()) {
    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);
}

Type guard

// Java
private static boolean hasCheckedItems(List<OmcCart> cartList) {
    return cartList != null && cartList.stream().anyMatch(OmcCart::getChecked);
}

Try / catch

try {
    OrderVo vo = orderService.createOrderDoc(loginAuthDto, shippingId);
} catch (OmcBizException e) {
    if (e.getCode() == ErrorCodeEnum.OMC10031001.getCode()) {
        return ResultHelper.fail(e.getCode(), "Your cart is empty or no items are selected");
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling createOrderDoc(loginAuthDto, shippingId) for a user whose cart has no checked items (or no cart items at all), or where getCartOrderItem filtered everything out so omcOrderDetailList is empty.

Common situations: User submits checkout from a stale page after unchecking/removing all items; checkout endpoint hit twice and items were already consumed; no items were ever checked (checkbox not set); cart data purged by a scheduled cleanup job.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcOrderServiceImpl.java:84

	private OmcCartMapper omcCartMapper;
	@Resource
	private OmcShippingMapper omcShippingMapper;
	@Resource
	private OmcCartService omcCartService;
	@Resource
	private OmcOrderDetailService omcOrderDetailService;

	@Resource
	private MdcProductService mdcProductService;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public OrderVo createOrderDoc(LoginAuthDto loginAuthDto, Long shippingId) {
		Long userId = loginAuthDto.getUserId();
		//从购物车中获取数据
		List<OmcCart> cartList = omcCartMapper.selectCheckedCartByUserId(userId);
		if (CollectionUtils.isEmpty(cartList)) {
			throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
		}
		//计算这个订单的总价
		List<OmcOrderDetail> omcOrderDetailList = omcCartService.getCartOrderItem(userId, cartList);

		if (CollectionUtils.isEmpty(omcOrderDetailList)) {
			throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
		}

		BigDecimal payment = this.getOrderTotalPrice(omcOrderDetailList);


		//生成订单
		OmcOrder order = this.assembleOrder(userId, shippingId, payment);
		if (order == null) {
			logger.error("生成订单失败, userId={}, shippingId={}, payment={}", userId, shippingId, payment);
			throw new OmcBizException(ErrorCodeEnum.OMC10031002);
		}
		order.setUpdateInfo(loginAuthDto);

View on GitHub (pinned to 781281a950)