apache/dolphinscheduler · error · ServiceException
10018
10018
Error message
project {0} not found What it means
ServiceException(Status.PROJECT_NOT_FOUND, code 10018) is thrown in grantProjectByCode when projectDao.queryByCode(projectCode) returns null, i.e. no project with that code exists. After the target user is validated, the project identified by its unique code cannot be found, so the grant cannot proceed. The message renders as 'project {0} not found ' with the supplied code.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java:592
* @param loginUser login user
* @param userId user id
* @param projectCode project code
* @return grant result code
*/
@Override
public void grantProjectByCode(final User loginUser, final int userId, final long projectCode) {
// 1. check if user is existed
User tempUser = this.userDao.queryById(userId);
if (tempUser == null) {
log.error("User does not exist, userId:{}.", userId);
throw new ServiceException(Status.USER_NOT_EXIST, userId);
}
// 2. check if project is existed
Project project = this.projectDao.queryByCode(projectCode);
if (project == null) {
log.error("Project does not exist, projectCode:{}.", projectCode);
throw new ServiceException(Status.PROJECT_NOT_FOUND, projectCode);
}
// 3. only project owner can operate
if (!this.canOperator(loginUser, project.getUserId())) {
log.warn("User does not have permission for project, userId:{}, userName:{}, projectCode:{}.",
loginUser.getId(), loginUser.getUserName(), projectCode);
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
// 4. maintain the relationship between project and user if not exists
ProjectUser projectUser = projectUserDao.queryProjectRelation(project.getId(), userId);
if (projectUser == null) {
Date today = new Date();
projectUser = new ProjectUser();
projectUser.setUserId(userId);
projectUser.setProjectId(project.getId());
projectUser.setPerm(Constants.AUTHORIZE_WRITABLE_PERM);
projectUser.setCreateTime(today);View on GitHub (pinned to 02eac45a1b)
Solutions
- Verify the projectCode exists via the project list/detail API before granting.
- Re-fetch the code from the projects endpoint rather than a stored snapshot.
- Ensure the long projectCode is transmitted without precision loss (use string in JSON clients).
- Catch ServiceException code 10018 and surface 'project not found' with the code in logs.
Example fix
// before
long code = Long.parseLong(request.getParameter("projectCode")); // may be garbage/0
usersService.grantProjectByCode(admin, userId, code);
// after
Project project = projectDao.queryByCode(code);
if (project == null) {
throw new IllegalArgumentException("projectCode " + code + " not found");
}
usersService.grantProjectByCode(admin, userId, code); Defensive patterns
Strategy: validation
Validate before calling
Project project = projectDao.queryByCode(projectCode);
if (project == null) {
throw new IllegalArgumentException("projectCode " + projectCode + " does not exist");
} Type guard
boolean projectExists(long projectCode) { return projectDao.queryByCode(projectCode) != null; } Try / catch
try {
usersService.grantProjectByCode(loginUser, userId, projectCode);
} catch (ServiceException e) {
if (e.getCode() == 10018) { /* project deleted: refresh code from projects API */ }
else throw e;
} Prevention
- Fetch project codes from the projects API at call time; do not persist them in jobs.
- Serialize the long projectCode as a string in JSON clients to avoid precision loss.
- Handle project deletion events by invalidating stored references.
When it happens
Trigger: Calling grantProjectByCode(loginUser, userId, projectCode) with a projectCode from a deleted project, a wrong environment, or a code parsed from a string/long incorrectly (e.g. truncated or 0 default).
Common situations: Project deleted by its owner while grant automation still references its code; copying projectCode from the wrong row of the UI URL; type coercion losing precision on the long code in some clients.
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
- url can not be null
- 10001
- namespace %s does not exist in k8s cluster, please create na
- Can not find any datasource by name %s
- Can not find valid workflow by name %s
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/33c1d71774496a7c.
Report an issue: GitHub.