floci-io/floci · error · AwsException

InvalidRequestException

InvalidRequestException

Error message

WorkGroup is required.

What it means

Raised by the Athena emulator's DeleteWorkGroup handler when the request has no WorkGroup field or the value fails the [a-zA-Z0-9._-]{1,128} pattern. It maps to AWS Athena's InvalidRequestException with HTTP 400, matching the real service's requirement that a workgroup name be present and well-formed.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/athena/AthenaJsonHandler.java:100

            case "ListDatabases" -> {
                String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
                yield Response.ok(Map.of("DatabaseList", athenaService.listDatabases(catalog))).build();
            }
            case "ListTableMetadata" -> {
                String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
                String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
                yield Response.ok(Map.of("TableMetadataList", athenaService.listTableMetadata(catalog, database))).build();
            }
            case "GetTableMetadata" -> {
                String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
                String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
                String tableName = request.get("TableName").asText();
                yield Response.ok(Map.of("TableMetadata", athenaService.getTableMetadata(catalog, database, tableName))).build();
            }
            case "DeleteWorkGroup" -> {
                String wg = request.path("WorkGroup").asText(null);
                if (wg == null || !wg.matches("[a-zA-Z0-9._-]{1,128}")) {
                    throw new AwsException("InvalidRequestException", "WorkGroup is required.", 400);
                }
                if ("primary".equals(wg)) {
                    throw new AwsException("InvalidRequestException", "The primary workgroup cannot be deleted.", 400);
                }
                athenaService.deleteWorkGroup(wg, region);
                yield Response.ok(Map.of()).build();
            }
            default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
        };
    }
}

View on GitHub (pinned to 62ff490619)

Solutions

  1. Pass a non-empty WorkGroup name: deleteWorkGroup(r -> r.workGroup("my-workgroup")).
  2. Validate the name against ^[a-zA-Z0-9._-]{1,128}$ before issuing the call.
  3. Check the request body actually includes WorkGroup (a typo'd builder method silently omits it).
  4. Note 'primary' is rejected separately — see the 'primary workgroup cannot be deleted' error.

Example fix

// before
athenaClient.deleteWorkGroup(r -> r.workGroup(System.getenv("WG")));

// after
String wg = System.getenv("WG");
if (wg == null || !wg.matches("[a-zA-Z0-9._-]{1,128}")) throw new IllegalArgumentException("WorkGroup required");
athenaClient.deleteWorkGroup(r -> r.workGroup(wg));
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern WG = Pattern.compile("[a-zA-Z0-9._-]{1,128}");
static void requireValidWorkGroup(String name) {
    if (name == null || !WG.matcher(name).matches())
        throw new IllegalArgumentException("WorkGroup is required and must match [a-zA-Z0-9._-]{1,128}");
}

Type guard

static boolean isValidWorkGroupName(String n) {
    return n != null && n.matches("[a-zA-Z0-9._-]{1,128}");
}

Try / catch

try {
    athenaClient.deleteWorkGroup(r -> r.workGroup(name));
} catch (InvalidRequestException e) {
    if (e.getMessage().contains("WorkGroup is required")) throw new IllegalArgumentException("name missing", e);
    throw e;
}

Prevention

When it happens

Trigger: Calling DeleteWorkGroup via the AWS SDK (athenaClient.deleteWorkGroup(r -> r.workGroup(""))) or CLI (aws athena delete-work-group) without a workgroup name, with an empty string, or with illegal characters (spaces, slashes, unicode).

Common situations: Scripts that build the request from a variable that is null/empty (e.g. missing env var or CLI flag), or name-generation code that introduces characters Athena forbids.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/b9e12c2250c25042. Report an issue: GitHub.