languagetool-org/languagetool · error · IllegalStateException

Could not fetch user information

Error message

Could not fetch user information

What it means

Inside handleGetUserInfoRequest, after authentication and premium-status checks, the handler reaches an else branch where it cannot determine which user information variant to return and throws an IllegalStateException('Could not fetch user information'). This is an internal guard for an unexpected request-state combination (e.g. an unrecognized 'authMethod' handling path or server-side user data problem), not a client-input validation error.

Source

Thrown at languagetool-server/src/main/java/org/languagetool/server/ApiV2.java:395

      } else if (authParameter.equals("addonToken")) {
        userInfo = DatabaseAccess.getInstance().getUserInfoWithAddonToken(user, password);
      } else if (authParameter.equals("apiKey")) {
        userInfo = DatabaseAccess.getInstance().getUserInfoWithApiKey(user, password);
      }

      String format = parameters.getOrDefault("format", "extended");
      if (userInfo != null) {
        if (format.equals("minimal")) {
          StringWriter sw = new StringWriter();
          new ObjectMapper().writeValue(sw, userInfo);
          sendJson(httpExchange, sw);
        } else {
          StringWriter sw = new StringWriter();
          new ObjectMapper().writeValue(sw, DatabaseAccess.getInstance().getExtendedUserInfo(user));
          sendJson(httpExchange, sw);
        }
      } else {
        throw new IllegalStateException("Could not fetch user information");
      }
    }
  }

  private void ensureGetMethod(HttpExchange httpExchange, String url) {
    if (!httpExchange.getRequestMethod().equalsIgnoreCase("get")) {
      throw new BadRequestException(url + " needs to be called with GET");
    }
  }
  
  private void ensurePostMethod(HttpExchange httpExchange, String url) {
    if (!httpExchange.getRequestMethod().equalsIgnoreCase("post")) {
      throw new BadRequestException(url + " needs to be called with POST");
    }
  }

  @NotNull
  private UserLimits getUserLimits(Map<String, String> parameters, HTTPServerConfig config) {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Retry with the default authMethod (omit the parameter) to take the standard password path.
  2. Check server logs for a preceding DatabaseAccess error indicating why user info could not be resolved.
  3. Verify client and server versions match so the authMethod values your client sends are handled by the server.
  4. If persistent, report it — this is an internal-state error rather than a request you can reshape.

Example fix

// before
GET /v2/users/me?authMethod=customMethod
// after
GET /v2/users/me
Defensive patterns

Strategy: try-catch

Try / catch

// HTTP 500 from an internal-state branch
try {
  const res = await fetch(usersMeUrl, { headers });
  if (res.status === 500) throw new Error('Server could not fetch user information; check server logs and authMethod support');
  return res.json();
} catch (e) { /* surface or retry with default authMethod */ }

Prevention

When it happens

Trigger: A request whose authentication outcome leaves the handler in an unhandled branch (e.g. premium-with-apiKey flows not matching the coded cases); server-side state where DatabaseAccess cannot resolve the user after the auth path was accepted.

Common situations: Custom or forked server builds where new authMethod values were added client-side but not server-side; database connectivity or migration issues leaving extended user info unresolvable.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/d8b70918f0d89fe6. Report an issue: GitHub.