paascloud/paascloud-master · error · OpcBizException
OPC10040008
OPC10040008
Error message
OPC10040008
What it means
OpcBizException with code OPC10040008 thrown by OptAttachmentServiceImpl.getById when selectByPrimaryKey returns no OptAttachment for the given attachmentId (null id is separately rejected by a Preconditions check). Any consumer of getById — e.g. rpcGetFileUrl building a file URL — cannot proceed without the attachment record's path and name.
Solutions
- Verify the attachment row exists for the id (select by primary key) before calling
- Have callers catch/handle OpcBizException OPC10040008 and return a friendly 'attachment not found' to users
- Confirm both sides operate on the same database/environment
- Fix deletion flows to invalidate or cascade references so stale ids are not used downstream
Example fix
// before
OptAttachment att = optAttachmentService.getById(attachmentId);
String fileName = att.getPath() + att.getName();
// after
OptAttachment att;
try {
att = optAttachmentService.getById(attachmentId);
} catch (OpcBizException e) {
log.warn("attachment {} not found", attachmentId);
throw new ResourceNotFoundException("Attachment not found: " + attachmentId);
}
String fileName = att.getPath() + att.getName(); Defensive patterns
Strategy: try-catch
Validate before calling
OptAttachment exists = optAttachmentMapper.selectByPrimaryKey(attachmentId);
if (exists == null) { throw new OpcBizException(ErrorCodeEnum.OPC10040008, attachmentId); } Type guard
if (attachmentId == null) { throw new IllegalArgumentException("文件流水号不能为空"); } Try / catch
try { att = service.getById(attachmentId); } catch (OpcBizException e) { throw new ResponseStatusException(NOT_FOUND, "attachment " + attachmentId + " not found"); } Prevention
- Catch OPC10040008 at the API layer and return 404-style responses
- Clean up downstream references when attachments are deleted
- Confirm the id originates from the same environment's DB
- Guard against id truncation/mapping errors between layers
When it happens
Trigger: getById called with an id of a deleted attachment row; a stale/cached id from the client after deletion; an id from a different environment/datasource; integer/string id truncation or mapping mistake producing a nonexistent key.
Common situations: rpcGetFileUrl invoked for an attachment removed by cleanup jobs; frontend link pointing at a purged file; cross-environment data (test id queried in prod); concurrent delete racing with the URL lookup.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/27112541a1459026.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java:229
}
private String getUrl(final Long expires, final boolean encrypt, final String fileName) {
final String domainOfBucket;
if (encrypt) {
domainOfBucket = paascloudProperties.getQiniu().getOss().getPrivateHost();
return optOssService.getFileUrl(domainOfBucket, fileName, expires);
} else {
domainOfBucket = paascloudProperties.getQiniu().getOss().getPublicHost();
return domainOfBucket + "/" + fileName;
}
}
@Override
public OptAttachment getById(Long attachmentId) {
Preconditions.checkArgument(attachmentId != null, "文件流水号不能为空");
OptAttachment optAttachment = optAttachmentMapper.selectByPrimaryKey(attachmentId);
if (PublicUtil.isEmpty(optAttachment)) {
throw new OpcBizException(ErrorCodeEnum.OPC10040008, attachmentId);
}
return optAttachment;
}
@Override
public OptUploadFileRespDto uploadFile(byte[] uploadBytes, String fileName, String fileType, String filePath, String bucketName, LoginAuthDto loginAuthDto) throws IOException {
OptUploadFileRespDto fileInfo = optOssService.uploadFile(uploadBytes, fileName, filePath, bucketName);
insertAttachment(fileType, bucketName, loginAuthDto, fileInfo);
return fileInfo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateAttachment(final UpdateAttachmentDto attachmentDto) throws QiniuException {
List<Long> attachmentIdList = attachmentDto.getAttachmentIdList();
LoginAuthDto loginAuthDto = attachmentDto.getLoginAuthDto();
String refNo = attachmentDto.getRefNo();
List<Long> idList = optAttachmentMapper.queryAttachmentByRefNo(refNo);View on GitHub (pinned to 781281a950)