{"record":{"id":"72383b3c57f701d4","repo":"languagetool-org/languagetool","slug":"you-must-specify-enabled-rules-or-categories-when","errorCode":null,"errorMessage":"You must specify enabled rules or categories when using enabledOnly=true","messagePattern":"You must specify enabled rules or categories when using enabledOnly=true","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"languagetool-server/src/main/java/org/languagetool/server/TextChecker.java","lineNumber":567,"sourceCode":"\n    if (shouldRunRestrictedRulesTest(params, agent, lang, abTest)) {\n      log.info(\"Running test with restricted rules for user: {}, language: {}, client: {}\",\n        params.getOrDefault(\"username\", \"\"), lang.getShortCodeWithCountryAndVariant(), agent);\n      useEnabledOnly = true;\n      enabledRules = onlyTestRules;\n      // need to clear these settings, leads to conflict with useEnabledOnly otherwise\n      disabledRules = Collections.emptyList();\n      disabledCategories = Collections.emptyList();\n    }\n\n\n    if ((disabledRules.size() > 0 || disabledCategories.size() > 0) && useEnabledOnly) {\n      ServerMetricsCollector.getInstance().logRequestError(ServerMetricsCollector.RequestErrorType.INVALID_REQUEST);\n      throw new BadRequestException(\"You cannot specify disabled rules or categories using enabledOnly=true\");\n    }\n    if (enabledRules.isEmpty() && enabledCategories.isEmpty() && useEnabledOnly) {\n      ServerMetricsCollector.getInstance().logRequestError(ServerMetricsCollector.RequestErrorType.INVALID_REQUEST);\n      throw new BadRequestException(\"You must specify enabled rules or categories when using enabledOnly=true\");\n    }\n\n    boolean enableTempOffRules = \"true\".equals(params.get(\"enableTempOffRules\"));\n    boolean useQuerySettings = enabledRules.size() > 0 || disabledRules.size() > 0 ||\n            enabledCategories.size() > 0 || disabledCategories.size() > 0 || enableTempOffRules;\n    boolean allowIncompleteResults = \"true\".equals(params.get(\"allowIncompleteResults\"));\n    JLanguageTool.Mode mode = ServerTools.getMode(params);\n    JLanguageTool.Level level = ServerTools.getLevel(params);\n    String[] toneTagNames = params.get(\"toneTags\") != null ? params.get(\"toneTags\").split(\",\") : null;\n    Set<ToneTag> toneTags = new HashSet<>(ToneTag.values().length);\n    if (toneTagNames != null) {\n      if (toneTagNames.length == 1 && toneTagNames[0].isEmpty()) { //&toneTags=\n        toneTags.add(ToneTag.ALL_WITHOUT_GOAL_SPECIFIC);\n      } else {\n        for (String toneTagName : toneTagNames) {\n          if (toneTagNames.length > 1 && (toneTagName.equals(\"NO_TONE_RULE\") || toneTagName.equals(\"ALL_TONE_RULES\"))) { //&toneTags=ALL_TONE_RULES or //&toneTags=NO_TONE_RULE\n            log.warn(\"NO_TONE_RULE and ALL_TONE_RULES will be ignored if more than one toneTag is in params.\");\n            continue;","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-server/src/main/java/org/languagetool/server/TextChecker.java#L549-L585","documentation":"enabledOnly=true restricts the check to explicitly enabled rules, so at least one enabled rule or category must be given. checkText throws BadRequestException when enabledOnly=true is set but both enabledRules and enabledCategories are empty, logging INVALID_REQUEST metrics.","triggerScenarios":"Sending /v2/check with enabledOnly=true and neither enabledRules nor enabledCategories parameters — the enable lists are empty so the request would match nothing.","commonSituations":"A UI toggle 'only check selected rules' switched on without any rules actually selected; programmatic clients that forward enabledOnly from config but compute enabled rule lists lazily/empty.","solutions":["Provide at least one rule id via enabledRules or one category via enabledCategories together with enabledOnly=true","Disable enabledOnly if you intend a full check with default rules","In client code, only send enabledOnly=true when the enabled-rule list is non-empty"],"exampleFix":"// before\ncurl -d text=... -d language=en-US -d enabledOnly=true http://server/v2/check\n// after\ncurl -d text=... -d language=en-US -d enabledOnly=true -d enabledRules=MORFOLOGIK_RULE_EN_US http://server/v2/check","handlingStrategy":"validation","validationCode":"if (params.enabledOnly && !(params.enabledRules?.length) && !(params.enabledCategories?.length)) {\n  throw new Error('enabledOnly=true requires enabledRules or enabledCategories');\n}","typeGuard":"function enabledOnlyIsValid(p) {\n  return !p.enabledOnly || (Array.isArray(p.enabledRules) && p.enabledRules.length > 0) || (Array.isArray(p.enabledCategories) && p.enabledCategories.length > 0);\n}","tryCatchPattern":null,"preventionTips":["Only flip enabledOnly on when at least one rule/category is selected in the UI/config","Assert the enabled list is non-empty in client tests","Fall back to a full check (drop enabledOnly) when the selection is empty"],"tags":["http-400","query-parameters","languagetool-server"],"backgroundTag":"missing-required-argument","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}