{"record":{"id":"b93fc8eea1486bac","repo":"jackwener/OpenCLI","slug":"instagram-private-publish-failed-to-stage","errorCode":null,"errorMessage":"Instagram private publish failed to ${stage}","messagePattern":"Instagram private publish failed to (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/private-publish.js","lineNumber":412,"sourceCode":"    }\n    return {\n        ...readImageAsset(outputPath),\n        cleanupPath: outputPath,\n    };\n}\nfunction runSwiftJsonScript(script, args, stage) {\n    const scriptPath = path.join(os.tmpdir(), `opencli-instagram-${crypto.randomUUID()}.swift`);\n    fs.writeFileSync(scriptPath, script);\n    try {\n        const result = spawnSync('swift', [scriptPath, ...args], {\n            encoding: 'utf8',\n        });\n        if (result.error || result.status !== 0) {\n            const detail = [result.error?.message, result.stderr, result.stdout]\n                .map((value) => String(value || '').trim())\n                .filter(Boolean)\n                .join(' ');\n            throw new CommandExecutionError(`Instagram private publish failed to ${stage}`, detail || 'swift helper failed');\n        }\n        return JSON.parse(String(result.stdout || '{}'));\n    }\n    catch (error) {\n        if (error instanceof CommandExecutionError)\n            throw error;\n        throw new CommandExecutionError(`Instagram private publish failed to ${stage}`, error instanceof Error ? error.message : String(error));\n    }\n    finally {\n        fs.rmSync(scriptPath, { force: true });\n    }\n}\nfunction readVideoMetadata(filePath) {\n    if (process.platform !== 'darwin') {\n        throw new CommandExecutionError(`Instagram private mixed-media publish does not support reading video metadata on ${process.platform}`, 'Use macOS for private mixed-media publishing, or rely on the UI fallback');\n    }\n    const metadata = runSwiftJsonScript(`\nimport AVFoundation","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/private-publish.js#L394-L430","documentation":"Generic wrapper for failures of the macOS `swift` helper script used by the private publish pipeline (reading video metadata, generating cover images, trimming story video). When the spawned swift process errors or exits non-zero, this error is thrown with the process output as detail.","triggerScenarios":"runSwiftJsonScript spawns a swift helper and result.error is set or result.status !== 0, during metadata extraction, cover image generation, or story video trimming.","commonSituations":"macOS host without a working swift toolchain (no Xcode command line tools), missing input video file, unsupported codec, timeout/OOM on large videos.","solutions":["Read the detail (swift stderr/stdout) for the exact failure","Install/repair the Xcode command line tools so `swift` runs (`xcode-select --install`)","Verify the input video path exists and is a playable mp4/mov","Pre-trim or pre-generate covers with ffmpeg and skip the swift helper step"],"exampleFix":"// before\nawait publish({ media: 'clip.mp4' }); // swift helper fails\n// after\n// $ xcode-select --install   # ensure swift toolchain\n// or pre-process: $ ffmpeg -i clip.mp4 -t 15 clip-trimmed.mp4\nawait publish({ media: 'clip-trimmed.mp4' });","handlingStrategy":"try-catch","validationCode":"const probe = spawnSync('swift', ['--version']);\nif (probe.error || probe.status !== 0) throw new Error('swift toolchain unavailable');\nif (!fs.existsSync(videoPath)) throw new Error(`missing video: ${videoPath}`);","typeGuard":null,"tryCatchPattern":"try {\n  await publish(cfg);\n} catch (e) {\n  if (/private publish failed to .+/.test(e.message)) {\n    // inspect e.detail for swift stderr; install CLT or pre-process with ffmpeg\n  } else throw e;\n}","preventionTips":["Install Xcode command line tools (`xcode-select --install`) on the macOS host","Validate video files exist and are playable before publish","Pre-trim videos / generate covers with ffmpeg to avoid the swift path","Keep the swift toolchain updated with macOS releases"],"tags":["macos","swift","video","process"],"backgroundTag":"swift-helper-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}