{"record":{"id":"5909315b5372a9f1","repo":"alibaba/nacos","slug":"fetchpagelimit-error","errorCode":null,"errorMessage":"fetchPageLimit error","messagePattern":"fetchPageLimit error","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java","lineNumber":74,"sourceCode":"    @Override\n    public Page<E> fetchPage(final String sqlCountRows, final String sqlFetchRows,\n        final Object[] args,\n        final int pageNo, final int pageSize, final RowMapper rowMapper) {\n        return fetchPage(sqlCountRows, sqlFetchRows, args, pageNo, pageSize, null, rowMapper);\n    }\n    \n    @Override\n    public Page<E> fetchPage(final String sqlCountRows, final String sqlFetchRows, Object[] args,\n        final int pageNo,\n        final int pageSize, final Long lastMaxId, final RowMapper rowMapper) {\n        if (pageNo <= 0 || pageSize <= 0) {\n            throw new IllegalArgumentException(\"pageNo and pageSize must be greater than zero\");\n        }\n        \n        // Query the total number of current records\n        Integer rowCountInt = databaseOperate.queryOne(sqlCountRows, args, Integer.class);\n        if (rowCountInt == null) {\n            throw new IllegalArgumentException(\"fetchPageLimit error\");\n        }\n        \n        // Count pages\n        int pageCount = rowCountInt / pageSize;\n        if (rowCountInt > pageSize * pageCount) {\n            pageCount++;\n        }\n        \n        // Create Page object\n        final Page<E> page = new Page<>();\n        page.setPageNumber(pageNo);\n        page.setPagesAvailable(pageCount);\n        page.setTotalCount(rowCountInt);\n        \n        if (pageNo > pageCount) {\n            return page;\n        }\n        ","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java#L56-L92","documentation":"Thrown by AuthEmbeddedPaginationHelperImpl.fetchPage when the SQL count query (sqlCountRows) returns null instead of an integer row count. This indicates the count SQL itself returned no result row — the database could not produce a count. The message 'fetchPageLimit error' is generic and does not reveal the underlying SQL issue.","triggerScenarios":"The sqlCountRows query references a table or column that does not exist in the embedded Derby schema, or the query has a syntax error that causes Derby to return no scalar result. This can happen after a schema migration that didn't apply to the auth tables, or if a custom SQL template is misconfigured.","commonSituations":"Auth plugin schema not initialized (embedded Derby auth tables missing); corrupted Derby database file; incomplete upgrade where auth DDL wasn't applied; custom SQL count template references a renamed column.","solutions":["Check the server logs for the actual Derby SQL error preceding this exception.","Verify auth-related Derby tables exist (e.g., permissions, roles, users) in the embedded database.","If the database is corrupted, stop the server, remove the embedded Derby data directory, and restart to reinitialize.","Ensure no custom auth SQL templates are overriding the default count queries incorrectly."],"exampleFix":"// Not a code fix — diagnose the SQL.\n// Enable debug logging for the embedded DB layer:\n// logging.level.com.alibaba.nacos.persistence.datasource=DEBUG\n// Then inspect the actual count SQL and Derby error in logs.\n// If tables are missing, reinitialize:\n//   1. Stop Nacos\n//   2. Remove {nacos.home}/data/derby-data\n//   3. Restart Nacos (schema auto-creates)","handlingStrategy":"try-catch","validationCode":"// Cannot prevent a null count result purely client-side.\n// Can pre-check that the embedded Derby data directory exists:\njava.nio.file.Path derbyDir = Paths.get(nacosHome, \"data\", \"derby-data\");\nif (!java.nio.file.Files.exists(derbyDir)) {\n    throw new IllegalStateException(\"Embedded Derby data directory not found\");\n}","typeGuard":"public static boolean isEmbeddedSchemaInitialized(Path nacosHome) {\n    return Files.exists(nacosHome.resolve(\"data/derby-data/nacos\"));\n}","tryCatchPattern":"try {\n    Page<E> page = paginationHelper.fetchPage(countSql, fetchSql, args, pageNo, pageSize, mapper);\n} catch (IllegalArgumentException e) {\n    if (\"fetchPageLimit error\".equals(e.getMessage())) {\n        logger.error(\"Count query returned null — check embedded Derby schema\", e);\n        throw new IllegalStateException(\"Auth database schema issue\", e);\n    }\n    throw e;\n}","preventionTips":["Ensure the Nacos server completes its schema initialization on first startup.","Monitor startup logs for Derby schema creation errors.","Keep backups of the embedded Derby data directory.","Avoid manually modifying or partially deleting Derby data files."],"tags":["pagination","embedded-db","auth-plugin","derby","database-error","sql"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}