code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Unhandled error event when using Figma connect

Open thomtreebus opened this issue 1 year ago • 1 comments

I'm trying to use the interactive setup to connect my design system to code connect. When asked for the URL of the Figma file with my design system library (step 3 in the guide), I get this error:

node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v21.7.1

I tried running swift run -c release --verbose figma-swift, which produced the following error:

error: binary operator '??' cannot be applied to operands of type '(output: String, changes: [Formatter.Change])?' and 'String'
225 | 
226 |     private func rewriteCodeBlockWithTemplate() -> String {
227 |         let formatted = (try? SwiftFormat.format(code.trimmedDescriptionRemovingReturnStatement())) ?? code.trimmedDescriptionRemovingReturnStatement()
    |                                                                                                     `- error: binary operator '??' cannot be applied to operands of type '(output: String, changes: [Formatter.Change])?' and 'String'
228 |         let tree = Parser.parse(source: formatted)
229 |         let rewriter = MappedPropertyRewriter(

path/to/project/.build/checkouts/code-connect/swiftui/lib/CodeConnectTemplateWriter.swift:249:35: error: cannot infer contextual base in reference to member 'whitespacesAndNewlines'
247 |         ).replaceNestedInstancePlaceholders(
248 |             nestedInstanceCalls: rewriter.nestedInstanceCalls
249 |         ).trimmingCharacters(in: .whitespacesAndNewlines)
    |                                   `- error: cannot infer contextual base in reference to member 'whitespacesAndNewlines'
250 |         
251 |         return "export default figma.swift`\(rewrittenCode)`"
  • Code Connect CLI version: 1.1.2
  • Operating system: OSX

figma.config for my SwiftUI project:

{
  "codeConnect": {
    "swiftPackagePath": "Package.swift",
    "include": ["Sources/**/**/*"],
    "exclude": ["markdown/**", "danger/**", "scripts/**", "SnapshotTests/**"]
  }
}

My Package.swift setup:

import PackageDescription

let package = Package(
    name: "ProjectName",
    defaultLocalization: "en",
    platforms: [
        .macOS(.v14),
        .iOS(.v16)
    ],
    products: [
        .library(name: "ProjectName", targets: ["ProjectTarget"])
    ],
    dependencies: [
        ...
        .package(url: "https://github.com/figma/code-connect", from: "1.0.0"),
    ],
    targets: [
        .target(name: "ProjectTarget",
            dependencies: [
                ...
                .product(name: "Figma", package: "code-connect")
            ],
            path: "Path/To/Project"
        )
    ]
)

thomtreebus avatar Dec 17 '24 11:12 thomtreebus

Hi @thomtreebus, thanks for the report! We've identified the issue and working on a fix.

In the meantime if you can force the version for SwiftFormat of 0.53.5 in your project that should fix the issue in the meantime. Sorry for the inconvenience.

slees-figma avatar Dec 18 '24 17:12 slees-figma