# "Internal Error ... Corrupted JSON" logged during builds

**URL:** <https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660>\
**Category:** Using Swift\
**Tags:** build\
**Created:** [June 24, 2026, 4:38pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660 "2026-06-24T16:38:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 4:38pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/1 "2026-06-24T16:38:39Z")

</div>

During command-line builds (`swift build`) I often see this disturbing message logged, sometimes multiple times:

`Internal Error: DecodingError.dataCorrupted: Data was corrupted. Debug description: Corrupted JSON. Underlying error: unexpected end of file`

It doesn't seem to cause any problems, but it's definitely not the kind of thing I'd expect to see repeatedly in a production toolchain. I've tried `swift package clean` but it doesn't make it go away.

I just searched the forum and didn't see any posts about it. Am I somehow the only person who gets this?

[Swift 6.3.2 on macOS, 6.3.0 on Linux]

---

<div class="post-metadata">

**Author:** ![bbrk24](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bbrk24/32/27370_2.png) [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Post date:** [June 24, 2026, 4:40pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/2 "2026-06-24T16:40:51Z")

</div>

> [@snej](#):
>
> I just searched the forum and didn't see any posts about it. Am I somehow the only person who gets this?

I've definitely seen this before, I've just been ignoring it. I've also been using a build tool (swift-bundler) rather than invoking `swift build` directly, so I wasn't sure if it was that.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [June 25, 2026, 2:05am UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/3 "2026-06-25T02:05:57Z")

</div>

> [@snej](#):
>
> Am I somehow the only person who gets this?

Yes, never seen this. It is usually because SwiftPM is constantly querying the Swift compiler for a JSON config about the host/target platform- seemingly too many times if you ask me- and maybe that communication gets garbled sometimes. Try running in very verbose mode with `--vv` and see if you can catch the failing command and [file an issue](https://github.com/swiftlang/swift-package-manager/issues).

---

<div class="post-metadata">

**Author:** ![Kyle-Ye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kyle-ye/32/19686_2.png) [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Post date:** [June 25, 2026, 3:39am UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/4 "2026-06-25T03:39:31Z")

</div>

> [@snej](#):
>
> Am I somehow the only person who gets this?

+1 for this. And I can reproduced it 100% after I bump my project to use 6.2/6.3. I did not got such log when I was using Swift 6.1 on Linux. So I believe there is some regression here either in swift compiler or swiftpm repo.

> I've also been using a build tool (swift-bundler) rather than invoking `swift build` directly, so I wasn't sure if it was that.

FYI: I'm just using the plain `swift build` here.

---

<div class="post-metadata">

**Author:** ![willft](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/willft/32/412_2.png) [@willft](https://forums.swift.org/u/willft)\
**Post date:** [June 25, 2026, 4:55pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/5 "2026-06-25T16:55:08Z")

</div>

I got this extremely frequently in Linux CI for a while. Using regular `swift build` and `swift test` . Just checked and our most recent builds don't have it - unsure what changed.

EDIT: Just saw it again but mine looks a little different: `Internal Error: DecodingError.dataCorrupted: Data was corrupted. Debug description: Corrupted JSON. Underlying error: unexpected end of file`

---

<div class="post-metadata">

**Author:** ![Kyle-Ye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kyle-ye/32/19686_2.png) [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Post date:** [June 30, 2026, 3:52pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/6 "2026-06-30T15:52:41Z")

</div>

> Note: This is an AI-assisted investigation summary and has not been manually confirmed yet. I plan to verify the findings myself and, if they hold up, submit a PR with the fix.

I did some investigation on `release/6.3` in a clean Ubuntu aarch64 environment.

I created a small `DemoKit` set of packages covering:

- a plain SwiftPM library package
- a build-tool-plugin package
- a macro package

The plain package and build-tool-plugin package did not reproduce the issue in my loops. The macro package did reproduce it with the system Swift 6.2.4 toolchain, especially when building with `--disable-experimental-prebuilts`:

```plaintext
Internal Error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Corrupted JSON", underlyingError: Optional(unexpected end of file)))

```

The failure appears to come from the macro / in-process plugin path, not the SwiftPM PackagePlugin IPC path.

The key finding is that `release/6.3` has a teardown path that sends an empty plugin message. That is fine as a stream-level termination signal for a pipe-backed executable plugin, but the in-process plugin server handles each `sendMessage` call as one complete JSON request and decodes it directly. When it receives the empty message, it tries to decode `""` as JSON, which produces the observed EOF / corrupted JSON diagnostic.

The relevant area is:

- `swift/lib/AST/PluginRegistry.cpp`
- `swift/include/swift/AST/PluginRegistry.h`
- `swift/tools/swift-plugin-server/Sources/SwiftInProcPluginServer/InProcPluginServer.swift`

A local fix that worked for me was:

1. Make the in-process plugin `sendMessage` path treat an empty message as a no-op, since there is no stream to tear down there.
2. Remove the teardown-time empty message expectation from the affected macro tests.

After applying that, I built a `release/6.3` Linux toolchain and reran the repro matrix:

```plaintext
3 packages x 3 build command variants x 50 iterations = 450 builds

```

I scanned all logs for:

```plaintext
Internal Error:
Corrupted JSON
unexpected end of file

```

and the issue did not reproduce anymore.

I also ran the targeted macro lit tests I touched; the relevant tests passed, with one unsupported on this Linux configuration.

So my current hypothesis is that this specific “Corrupted JSON / unexpected end of file” diagnostic is caused by an empty teardown message being routed through the in-process macro plugin JSON decoder. I will follow up after manually confirming the repro and the fix.

---

<div class="post-metadata">

**Author:** ![rintaro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rintaro/32/568_2.png) [@rintaro](https://forums.swift.org/u/rintaro)\
**Post date:** [July 20, 2026, 9:41pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/8 "2026-07-20T21:41:32Z")

</div>

I _think_ this is the same issue as [Compiler emits error `Internal Error: dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Corrupted JSON", underlyingError: Optional(unexpected end of file)))` repeatedly during build · Issue #86833 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/issues/86833) and your package is referring a swift-syntax before [[Macros] Termination signal for executable plugin by rintaro · Pull Request #3164 · swiftlang/swift-syntax · GitHub](https://github.com/swiftlang/swift-syntax/pull/3164)

Could you check if the version of swift-syntax dependency is `603.0.0` or later? Note that specifying lower major version with `from:` never resolves it to next major version (i.e. `from: "602.0.0"` is not resolved to 603+)

> [@Kyle-Ye](#):
>
> A local fix that worked for me was:
> 
> 1. Make the in-process plugin `sendMessage` path treat an empty message as a no-op, since there is no stream to tear down there.
> 2. Remove the teardown-time empty message expectation from the affected macro tests.
> 
> After applying that, I built a `release/6.3` Linux toolchain and reran the repro matrix:

In-process plugin path should never receive empty message, and there's no test cases expecting it as far as I can tell.

---

<div class="post-metadata">

**Author:** ![Kyle-Ye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kyle-ye/32/19686_2.png) [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Post date:** [July 21, 2026, 5:46pm UTC](https://forums.swift.org/t/internal-error-corrupted-json-logged-during-builds/87660/9 "2026-07-21T17:46:38Z")

</div>

I was using 601. Update to 603 did solve the issue. Thanks. @rintaro
