{"record":{"id":"0c49a35801232262","repo":"apache/iceberg","slug":"malformed-request-s","errorCode":null,"errorMessage":"Malformed request: %s","messagePattern":"Malformed request: (.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java","lineNumber":276,"sourceCode":"          throw new AlreadyExistsException(\"%s\", error.message());\n      }\n\n      super.accept(error);\n    }\n  }\n\n  /** Request error handler specifically for create-read-update ops on namespaces. */\n  private static class NamespaceErrorHandler extends DefaultErrorHandler {\n    private static final ErrorHandler INSTANCE = new NamespaceErrorHandler();\n\n    @Override\n    public void accept(ErrorResponse error) {\n      switch (error.code()) {\n        case 400:\n          if (NamespaceNotEmptyException.class.getSimpleName().equals(error.type())) {\n            throw new NamespaceNotEmptyException(\"%s\", error.message());\n          }\n          throw new BadRequestException(\"Malformed request: %s\", error.message());\n        case 404:\n          throw new NoSuchNamespaceException(\"%s\", error.message());\n        case 409:\n          throw new AlreadyExistsException(\"%s\", error.message());\n        case 422:\n          throw createRESTException(error);\n      }\n\n      super.accept(error);\n    }\n  }\n\n  /** Request error handler for drop namespace operations. */\n  private static class DropNamespaceErrorHandler extends NamespaceErrorHandler {\n    private static final ErrorHandler INSTANCE = new DropNamespaceErrorHandler();\n\n    @Override\n    public void accept(ErrorResponse error) {","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java#L258-L294","documentation":"The NamespaceErrorHandler converts an HTTP 400 from the server into BadRequestException('Malformed request: %s') when the error type is not 'NamespaceNotEmptyException'. The library throws this when it cannot map the bad request to a more specific namespace exception, indicating the request body/parameters were rejected by the server as invalid.","triggerScenarios":"Namespace REST calls (createNamespace, setProperties, removeProperties, listNamespaces) where the server responds 400 with an ErrorResponse whose type field is null or unrecognized - e.g. invalid namespace syntax in the request, malformed JSON payload, unsupported properties payload.","commonSituations":"Namespace names containing characters the server rejects; sending multi-level namespaces to a catalog expecting a different separator; client/server spec version skew causing schema mismatches; hand-crafted REST requests with invalid bodies.","solutions":["Read the server-provided message after 'Malformed request:' - it names the specific validation the server rejected.","Validate the namespace identifier format for the target catalog (allowed characters, level count, separator).","Upgrade/align the iceberg-rest client version with the server's REST spec version if payloads changed.","If the server meant 'namespace not empty' but did not set the type field, fix the server (or upgrade it) so it returns type NamespaceNotEmptyException."],"exampleFix":"// before\nString ns = \"my/ns/with/slashes\"; // server rejects\ncatalog.createNamespace(Namespace.of(ns));\n// after\nNamespace ns = Namespace.of(\"my_namespace\");\ncatalog.createNamespace(ns);","handlingStrategy":"validation","validationCode":"Preconditions.checkArgument(ns.levels().length > 0 && ns.levels()[0].matches(\"[A-Za-z0-9_-]+\"), \"invalid namespace\");","typeGuard":null,"tryCatchPattern":"catch (BadRequestException e) { log.error(\"Server rejected request: {}\", e.getMessage()); /* fix request, do not retry */ }","preventionTips":["Validate namespace identifier characters and hierarchy client-side","Keep iceberg client and REST server versions spec-compatible","Never auto-retry 400 responses - fix the request payload instead"],"tags":["rest-catalog","http-400","bad-request","namespace"],"backgroundTag":"http-request-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}