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

  1. Verify the projectCode exists via the project list/detail API before granting.
  2. Re-fetch the code from the projects endpoint rather than a stored snapshot.
  3. Ensure the long projectCode is transmitted without precision loss (use string in JSON clients).
  4. 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

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


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/33c1d71774496a7c. Report an issue: GitHub.