{"record":{"id":"501749411bfbf565","repo":"gradle/gradle","slug":"could-not-determine-s-metadata-s-produced-unexp-501749","errorCode":null,"errorMessage":"Could not determine %s metadata: %s produced unexpected output.","messagePattern":"Could not determine (.+?) metadata: (.+?) produced unexpected output\\.","errorType":"exception","errorClass":"BrokenResultException","httpStatus":null,"severity":"error","filePath":"platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/swift/metadata/SwiftcMetadataProvider.java","lineNumber":78,"sourceCode":"    @Override\n    protected SwiftcMetadata parseCompilerOutput(String stdout, String stderr, File swiftc, List<File> path) {\n        BufferedReader reader = new BufferedReader(new StringReader(stdout));\n        try {\n            String line;\n            while ((line = reader.readLine()) != null) {\n                if (line.contains(\"Swift version\")) {\n                    String[] tokens = line.split(\" \");\n                    // Assuming format: 'Swift version 4.0.2 (...)'\n                    int i = 2;\n                    if (\"Apple\".equals(tokens[0])) {\n                        // Actual format: 'Apple Swift version 4.0.2 (...)'\n                        i++;\n                    }\n                    VersionNumber version = VersionNumber.parse(tokens[i]);\n                    return new DefaultSwiftcMetadata(line, version);\n                }\n            }\n            throw new BrokenResultException(String.format(\"Could not determine %s metadata: %s produced unexpected output.\", getCompilerType().getDescription(), swiftc.getName()));\n        } catch (IOException e) {\n            // Should not happen when reading from a StringReader\n            throw UncheckedException.throwAsUncheckedException(e);\n        }\n    }\n\n    private static class DefaultSwiftcMetadata implements SwiftcMetadata {\n        private final String versionString;\n        private final VersionNumber version;\n\n        DefaultSwiftcMetadata(String versionString, VersionNumber version) {\n            this.versionString = versionString;\n            this.version = version;\n        }\n\n        @Override\n        public String getVendor() {\n            return versionString;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/swift/metadata/SwiftcMetadataProvider.java#L60-L96","documentation":"SwiftcMetadataProvider runs `swiftc --version` and scans stdout for a line containing 'Swift version', parsing the version from token index 2 ('Swift version 4.0.2 (...)') or index 3 when the line starts with 'Apple' ('Apple Swift version 4.0.2 (...)'). If no line matches, BrokenResultException 'Could not determine SwiftC metadata: <binary> produced unexpected output' is thrown.","triggerScenarios":"A swiftc whose --version banner does not contain the literal substring 'Swift version': development snapshots print 'Swift compiler version 6.0-dev ...' (the word 'compiler' breaks the match); non-Apple custom builds with a different banner; tokens[2]/tokens[3] not being a parseable version; empty stdout when the binary is a broken shim.","commonSituations":"Using a swift.org DEVELOPMENT/main-snapshot toolchain (banner 'Swift compiler version ...') with an older Gradle; aliasing swiftc to a wrapper that swallows stdout; Swift toolchains from unusual vendors on CI.","solutions":["Run `swiftc --version` yourself and check a line contains 'Swift version <n.n.n>'; if it reads 'Swift compiler version ...', switch to a release toolchain (banner 'Swift version ...').","Point the Swift toolchain configuration at the real swiftc binary, not a wrapper.","Upgrade Gradle - newer metadata providers parse development-snapshot banners too."],"exampleFix":"# before\n$ swiftc --version\nSwift compiler version 6.0 (swift-6.0-DEVELOPMENT)   # no 'Swift version' line -> error\n# after: install/use a release toolchain\n$ swiftc --version\nSwift version 5.10 (swift-5.10-RELEASE)\nTarget: x86_64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"def out = 'swiftc --version'.execute().in.text\nif (!out.readLines().any { it.contains('Swift version') }) {\n    throw new GradleException('swiftc --version has no \"Swift version\" line (dev snapshot or wrapper?); install a release toolchain')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use release Swift toolchains with Gradle; development snapshots print 'Swift compiler version' banners this parser rejects.","Point the Swift toolchain path at the real swiftc, not a wrapper script.","Add a CI preflight running swiftc --version and asserting the banner format."],"tags":["gradle","swift","swiftc","compiler-detection","version-parsing"],"backgroundTag":"compiler-probe-unexpected-output","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}