apache/dolphinscheduler · error · ServiceException
limit must be -1 or greater than 0
Error message
limit must be -1 or greater than 0
What it means
FetchFileContentDtoValidator.validate throws this ServiceException when limit is neither -1 (meaning 'return all remaining lines') nor a positive number, i.e. it is 0 or any negative value other than -1.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java:41
import org.apache.dolphinscheduler.dao.repository.TenantDao;
import org.apache.dolphinscheduler.plugin.storage.api.StorageOperator;
import org.springframework.stereotype.Component;
@Component
public class FetchFileContentDtoValidator extends AbstractResourceValidator<FetchFileContentDto> {
public FetchFileContentDtoValidator(StorageOperator storageOperator, TenantDao tenantDao) {
super(storageOperator, tenantDao);
}
@Override
public void validate(FetchFileContentDto fetchFileContentDto) {
if (fetchFileContentDto.getSkipLineNum() < 0) {
throw new ServiceException("skipLineNum must be greater than or equal to 0");
}
if (fetchFileContentDto.getLimit() != -1 && fetchFileContentDto.getLimit() <= 0) {
throw new ServiceException("limit must be -1 or greater than 0");
}
String resourceFileAbsolutePath = fetchFileContentDto.getResourceFileAbsolutePath();
User loginUser = fetchFileContentDto.getLoginUser();
exceptionResourceAbsolutePathInvalidated(resourceFileAbsolutePath);
exceptionResourceIsNotFile(resourceFileAbsolutePath);
exceptionUserNoResourcePermission(loginUser, resourceFileAbsolutePath);
exceptionFileContentCannotFetch(resourceFileAbsolutePath);
}
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Use limit = -1 to fetch the whole file, or a positive integer for paged reads.
- Clamp client-side page sizes: ensure pageSize > 0 before building the request.
- Map any 'unlimited' sentinel in your code to -1 before calling the API.
Example fix
// before fetchFileContent(loginUser, path, 0, 0); // 0 rejected // after fetchFileContent(loginUser, path, 0, -1); // whole file // or fetchFileContent(loginUser, path, 0, 100); // first 100 lines
Defensive patterns
Strategy: validation
Validate before calling
if (limit != -1 && limit <= 0) { throw new IllegalArgumentException("limit must be -1 or > 0"); } Type guard
boolean isValidLimit(int limit) { return limit == -1 || limit > 0; } Prevention
- Use -1 as the only sentinel for 'unlimited'; never 0.
- Ensure computed page sizes are positive before sending requests.
- Document limit semantics (-1 = all) in client SDK wrappers.
When it happens
Trigger: Calling the read-file-content API with limit = 0, -2, or other invalid values; only limit == -1 and limit > 0 are accepted.
Common situations: Client using 0 as a sentinel for 'unlimited' instead of -1; broken pagination math yielding 0-sized pages; copy-pasted code from APIs where 0 means unlimited.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- skipLineNum must be greater than or equal to 0
- The path is not a directory: ${directoryAbsolutePath}
- 10001
- DESCRIPTION_TOO_LONG_ERROR
- ENVIRONMENT_NAME_IS_NULL
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/d3b289134bc41796.
Report an issue: GitHub.