{"record":{"id":"5d8378dd83ebb1ad","repo":"apache/seatunnel","slug":"file-format-canal-json-does-not-support-reading","errorCode":null,"errorMessage":"File format 'canal_json' does not support reading.","messagePattern":"File format 'canal_json' does not support reading\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/config/FileFormat.java","lineNumber":148,"sourceCode":"        @Override\n        public WriteStrategy getWriteStrategy(FileSinkConfig fileSinkConfig) {\n            return new BinaryWriteStrategy(fileSinkConfig);\n        }\n\n        @Override\n        public ReadStrategy getReadStrategy() {\n            return new BinaryReadStrategy();\n        }\n    },\n    CANAL_JSON(\"canal_json\") {\n        @Override\n        public WriteStrategy getWriteStrategy(FileSinkConfig fileSinkConfig) {\n            return new CanalJsonWriteStrategy(fileSinkConfig);\n        }\n\n        @Override\n        public ReadStrategy getReadStrategy() {\n            throw new UnsupportedOperationException(\n                    \"File format 'canal_json' does not support reading.\");\n        }\n    },\n    DEBEZIUM_JSON(\"debezium_json\") {\n        @Override\n        public WriteStrategy getWriteStrategy(FileSinkConfig fileSinkConfig) {\n            return new DebeziumJsonWriteStrategy(fileSinkConfig);\n        }\n\n        @Override\n        public ReadStrategy getReadStrategy() {\n            throw new UnsupportedOperationException(\n                    \"File format 'debezium_json' does not support reading.\");\n        }\n    },\n    MAXWELL_JSON(\"maxwell_json\") {\n        @Override\n        public WriteStrategy getWriteStrategy(FileSinkConfig fileSinkConfig) {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/config/FileFormat.java#L130-L166","documentation":"The CANAL_JSON FileFormat enum member only implements a write strategy (CanalJsonWriteStrategy). Calling getReadStrategy() on it throws UnsupportedOperationException because canal-json files cannot be read back as a regular file source format.","triggerScenarios":"Configuring a file source (or any code path that resolves a ReadStrategy) with format = \"canal_json\"; FileFormat.valueOf(...).getReadStrategy() is invoked during source initialization.","commonSituations":"Copy-pasting a sink config into a source job; assuming CDC JSON formats are bidirectional; docs/examples mismatch across SeaTunnel versions.","solutions":["Use a format that supports reading (e.g. text, csv, json, parquet, orc) for the file source.","Use the MySQL-CDC connector to consume canal-style change data instead of a file source.","Wrap the format resolution with a capability check (FileFormat supports getReadStrategy) before selecting the format.","If write-only output is what you need, keep canal_json only on sink configs."],"exampleFix":"// before\nsource {\n  LocalFile {\n    format = \"canal_json\"\n  }\n}\n// after\nsource {\n  LocalFile {\n    format = \"json\"\n  }\n}","handlingStrategy":"validation","validationCode":"FileFormat fmt = FileFormat.valueOf(config.get(\"format\"));\ntry {\n    fmt.getReadStrategy();\n} catch (UnsupportedOperationException e) {\n    throw new IllegalArgumentException(\"Format \" + fmt + \" cannot be used as a file source\");\n}","typeGuard":"boolean isReadable(FileFormat fmt) {\n    try { fmt.getReadStrategy(); return true; }\n    catch (UnsupportedOperationException e) { return false; }\n}","tryCatchPattern":"try {\n    sourceConfig.getFormat().getReadStrategy();\n} catch (UnsupportedOperationException e) {\n    log.error(\"This file format supports writing only; switch to a readable format\", e);\n    throw new IllegalArgumentException(e);\n}","preventionTips":["Check format read/write capability in docs before choosing it for a source.","Never use CDC JSON formats (canal_json/debezium_json/maxwell_json) in source jobs.","Add a config linter that probes FileFormat.getReadStrategy for sources.","When migrating sink configs to sources, audit the format field first."],"tags":["file-connector","file-format","unsupported-read","cdc-json"],"backgroundTag":"operation-not-supported","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}