{"record":{"id":"733789e6a7e6247c","repo":"halo-dev/halo","slug":"the-required-parameter-commentname-is-missing","errorCode":null,"errorMessage":"The required parameter 'commentName' is missing.","messagePattern":"The required parameter 'commentName' is missing\\.","errorType":"http","errorClass":"ServerWebInputException","httpStatus":400,"severity":"warning","filePath":"application/src/main/java/run/halo/app/content/comment/ReplyQuery.java","lineNumber":35,"sourceCode":"import run.halo.app.extension.router.SortableRequest;\n\n/**\n * Query criteria for {@link Reply} list.\n *\n * @author guqing\n * @since 2.0.0\n */\npublic class ReplyQuery extends SortableRequest {\n\n    public ReplyQuery(ServerWebExchange exchange) {\n        super(exchange);\n    }\n\n    /** Metadata name of the comment whose replies should be listed. */\n    public String getCommentName() {\n        String commentName = queryParams.getFirst(\"commentName\");\n        if (StringUtils.isBlank(commentName)) {\n            throw new ServerWebInputException(\"The required parameter 'commentName' is missing.\");\n        }\n        return commentName;\n    }\n\n    /** Build list options from query criteria. */\n    public ListOptions toListOptions() {\n        var listOptions = labelAndFieldSelectorToListOptions(getLabelSelector(), getFieldSelector());\n        var newFieldSelector = listOptions.getFieldSelector().andQuery(equal(\"spec.commentName\", getCommentName()));\n        listOptions.setFieldSelector(newFieldSelector);\n        return listOptions;\n    }\n\n    public PageRequest toPageRequest() {\n        var sort = getSort().and(Sort.by(\"spec.creationTime\").ascending());\n        return PageRequestImpl.of(getPage(), getSize(), sort);\n    }\n\n    public static void buildParameters(Builder builder) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/halo-dev/halo/blob/d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8/application/src/main/java/run/halo/app/content/comment/ReplyQuery.java#L17-L53","documentation":"ReplyQuery.getCommentName() reads the commentName query parameter used to scope a reply listing. It throws ServerWebInputException (HTTP 400) when the parameter is missing or blank. The same value is reused in toListOptions() to build the field selector, so a blank commentName would produce an ambiguous query — hence the early guard.","triggerScenarios":"GET request to the replies listing endpoint without a commentName query param, or with commentName=& (empty), or with only whitespace. Calling getCommentName() twice-free in custom code that forgets to pass the param.","commonSituations":"Frontend bug dropping the commentName query string when navigating/paginating replies; a client constructing the URL programmatically and omitting the parameter; theme code linking to the reply endpoint without the comment reference.","solutions":["Always include ?commentName=<comment metadata name> on the replies request.","On the client, assert commentName is present before issuing the request.","If listing all replies is genuinely needed, use a different endpoint that supports an unscoped query rather than dropping the parameter."],"exampleFix":"// before\nfetch('/apis/api.console.halo.run/v1alpha1/commenters/replies') // 400\n\n// after\nfetch(`/apis/api.console.halo.run/v1alpha1/commenters/replies?commentName=${encodeURIComponent(commentName)}`)","handlingStrategy":"validation","validationCode":"String commentName = exchange.getRequest().getQueryParams().getFirst(\"commentName\");\nif (!StringUtils.hasText(commentName)) {\n    return Mono.error(new ServerWebInputException(\"commentName required\"));\n}\nnew ReplyQuery(exchange).toListOptions();","typeGuard":"static boolean hasCommentName(ServerWebExchange ex) {\n    return StringUtils.hasText(\n        ex.getRequest().getQueryParams().getFirst(\"commentName\"));\n}","tryCatchPattern":null,"preventionTips":["Always attach ?commentName=<name> when requesting replies.","On the frontend, require a selected comment before loading its replies.","Unit-test reply listing code with the parameter present."],"tags":["validation","query-param","comment","http-400","required-field"],"backgroundTag":null,"analyzedSha":"d2f5165f9c8f055ffcb3fa9c3f4032821a7b68c8","analyzedAt":"2026-08-14T00:18:38.915Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}