apache/dolphinscheduler · warning · ServiceException
ENVIRONMENT_WORKER_GROUPS_IS_INVALID
ENVIRONMENT_WORKER_GROUPS_IS_INVALID
Error message
ENVIRONMENT_WORKER_GROUPS_IS_INVALID
What it means
Thrown by checkParams when workerGroups is non-empty but is not valid JSON. checkParams attempts JSONUtils.parseObject into a List<String> and converts IllegalArgumentException into this error, so malformed worker group JSON is rejected early.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java:433
throw new ServiceException(Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR, workerGroup,
environmentName, collect);
}
}
}
protected void checkParams(String name, String config, String workerGroups) {
if (StringUtils.isEmpty(name)) {
throw new ServiceException(Status.ENVIRONMENT_NAME_IS_NULL);
}
if (StringUtils.isEmpty(config)) {
throw new ServiceException(Status.ENVIRONMENT_CONFIG_IS_NULL);
}
if (StringUtils.isNotEmpty(workerGroups)) {
try {
JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {
});
} catch (IllegalArgumentException e) {
throw new ServiceException(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID);
}
}
}
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Send a proper JSON array of strings, e.g. \"[\"groupA\"]\"
- Escape quotes correctly when embedding in shell or JSON payloads
- Use JSONUtils.toJsonString(list) (or equivalent) on the client instead of string concatenation
- Validate the JSON payload with a linter before sending
Example fix
// before String workerGroups = "[groupA, groupB]"; // invalid JSON -> throws // after String workerGroups = "[\"groupA\",\"groupB\"]";
Defensive patterns
Strategy: validation
Validate before calling
if (workerGroups != null && !workerGroups.isEmpty()) {
try {
JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {});
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("workerGroups must be a JSON array of strings");
}
} Try / catch
try {
environmentService.createEnvironment(loginUser, name, desc, config, workerGroups);
} catch (ServiceException e) {
if (e.getCode() == Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID.getCode()) {
// fix JSON formatting and retry
} else { throw e; }
} Prevention
- Always serialize worker group lists with a JSON library, never string concat
- Validate payloads with a JSON parser before sending
- Quote strings properly when building JSON in shell scripts
When it happens
Trigger: Passing workerGroups like "groupA" or "[groupA]" (unquoted) instead of a JSON array such as "[\"groupA\"]" to createEnvironment or updateEnvironmentByCode.
Common situations: Shell scripts building JSON manually without quoting; copying workerGroups from logs with stripped escapes; UI bug sending a comma-separated string; passing a Java List's toString() output.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR
- DESCRIPTION_TOO_LONG_ERROR
- ENVIRONMENT_NAME_EXISTS
- CREATE_ENVIRONMENT_ERROR
- QUERY_ENVIRONMENT_BY_CODE_ERROR
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/9b9baebe2ee39f94.
Report an issue: GitHub.