paascloud/paascloud-master · error · OmcBizException

OMC10031001

OMC10031001

Error message

OMC10031001

What it means

OMC10031001 means '购物车为空' (cart is empty, userId=%s). getCartOrderItem builds order details from a cart list, and if the caller passes a null/empty list there is nothing to convert into OmcOrderDetail rows, so the service throws OmcBizException instead of silently producing an empty order.

Solutions

  1. Check CollectionUtils.isEmpty(cartList) before calling getCartOrderItem and handle the empty-cart case in the UI (redirect to cart page with a message).
  2. Ensure the cart has checked/selected items before invoking checkout — selectCheckedCartByUserId only returns checked items.
  3. Catch OmcBizException and map code 10031001 to a user-facing 'your cart is empty' response rather than a 500.
  4. If the cart should never be empty, add an earlier guard when items are removed so checkout is disabled client-side.

Example fix

// before
List<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);
// after
if (CollectionUtils.isEmpty(cartList)) {
    return ResultHelper.fail(ErrorCodeEnum.OMC10031001, userId);
}
List<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);
Defensive patterns

Strategy: validation

Validate before calling

// Java, before calling the service
if (cartList == null || cartList.isEmpty()) {
    throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId); // or return an empty-cart result
}

Type guard

// Java
private static boolean hasItems(List<OmcCart> cartList) {
    return cartList != null && !cartList.isEmpty();
}

Try / catch

try {
    List<OmcOrderDetail> items = omcCartService.getCartOrderItem(userId, cartList);
} catch (OmcBizException e) {
    if (e.getCode() == ErrorCodeEnum.OMC10031001.getCode()) {
        return ResultHelper.fail(e.getCode(), "Your cart is empty");
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling omcCartService.getCartOrderItem(userId, cartList) with an empty or null cartList — e.g. after the user's checked cart items were deleted, or a caller builds the cart list itself and passes it unvalidated.

Common situations: User empties their cart in one session/tab then checks out from a stale page; the checked-cart query (selectCheckedCartByUserId) returns nothing because no items are checked; cart records were purged between page load and order creation.

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/ce22a4422d4e8637. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java:310

		}

		orderProductVo.setProductTotalPrice(payment);
		orderProductVo.setOrderItemVoList(orderItemVoList);

		return orderProductVo;
	}

	private boolean getAllCheckedStatus(Long userId) {
		Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
		return omcCartMapper.selectUnCheckedCartProductCountByUserId(userId) == 0;

	}

	@Override
	public List<OmcOrderDetail> getCartOrderItem(Long userId, List<OmcCart> cartList) {
		List<OmcOrderDetail> orderItemList = Lists.newArrayList();
		if (CollectionUtils.isEmpty(cartList)) {
			throw new OmcBizException(ErrorCodeEnum.OMC10031001, userId);
		}

		//校验购物车的数据,包括产品的状态和数量
		for (OmcCart cartItem : cartList) {
			OmcOrderDetail orderDetail = new OmcOrderDetail();
			ProductDto product = mdcProductService.selectById(cartItem.getProductId());
			if (MdcApiConstant.ProductStatusEnum.ON_SALE.getCode() != product.getStatus()) {
				logger.error("商品不是在线售卖状态, productId={}", product.getId());
				throw new OmcBizException(ErrorCodeEnum.MDC10021015, product.getId());
			}

			//校验库存
			if (cartItem.getQuantity() > product.getStock()) {
				logger.error("商品库存不足, productId={}", product.getId());
				throw new OmcBizException(ErrorCodeEnum.MDC10021016, product.getId());
			}

			orderDetail.setUserId(userId);

View on GitHub (pinned to 781281a950)