{"record":{"id":"9ee89964009f9ac7","repo":"apache/iceberg","slug":"failed-to-write-json-to-file-s-9ee899","errorCode":null,"errorMessage":"Failed to write json to file: %s","messagePattern":"Failed to write json to file: (.+?)","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/view/ViewMetadataParser.java","lineNumber":199,"sourceCode":"      return fromJson(file.location(), JsonUtil.mapper().readValue(is, JsonNode.class));\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          String.format(\"Failed to read json file: %s\", file.location()), e);\n    }\n  }\n\n  private static void internalWrite(\n      ViewMetadata metadata, OutputFile outputFile, boolean overwrite) {\n    boolean isGzip = Codec.fromFileName(outputFile.location()) == Codec.GZIP;\n    OutputStream stream = overwrite ? outputFile.createOrOverwrite() : outputFile.create();\n    try (OutputStreamWriter writer =\n            new OutputStreamWriter(\n                isGzip ? new GZIPOutputStream(stream) : stream, StandardCharsets.UTF_8);\n        JsonGenerator generator = JsonUtil.factory().createGenerator(writer)) {\n      toJson(metadata, generator);\n      generator.flush();\n    } catch (IOException e) {\n      throw new UncheckedIOException(\n          String.format(\"Failed to write json to file: %s\", outputFile.location()), e);\n    }\n  }\n}\n","sourceCodeStart":181,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/view/ViewMetadataParser.java#L181-L204","documentation":"ViewMetadataParser.internalWrite wraps IOExceptions from writing (and JSON-generating) the view metadata to an OutputFile in an UncheckedIOException with this message. It signals the metadata JSON could not be serialized or durably written to the target location.","triggerScenarios":"Writing view metadata to a location without write permission, an unreachable object store, full disk, or when toJson fails due to an unserializable field; gzip output stream errors.","commonSituations":"Catalogs writing to storage with expired credentials; network partitions to S3/HDFS/GCS during commit; setting an invalid or unwritable write.metadata.path for views.","solutions":["Check storage credentials and permissions for the metadata location","Verify network connectivity to the object store/filesystem","Confirm the target location is valid and not read-only","Retry the commit; transient IO failures usually clear on retry"],"exampleFix":"// before\nViewMetadataParser.write(metadata, outputFile);\n// after\ntry {\n  ViewMetadataParser.overwrite(metadata, outputFile);\n} catch (UncheckedIOException e) {\n  LOG.error(\"Failed writing view metadata to {}\", outputFile.location(), e);\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// verify write access before committing metadata\nboolean writable = outputFile.location().startsWith(validMetadataRoot);","typeGuard":null,"tryCatchPattern":"try { ViewMetadataParser.overwrite(metadata, outputFile); } catch (UncheckedIOException e) { LOG.error(\"write failed: {}\", outputFile.location(), e); throw e; }","preventionTips":["Ensure storage credentials are valid before long transactions","Point write.metadata.path to a writable, reachable location","Retry commits on transient object-store IO failures"],"tags":["io","json","file-write","view-metadata"],"backgroundTag":"file-write-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}