* Track update failure event to PostHog. * Fire-and-forget - errors are silently ignored.
(errorMessage, version, context = {})
| 119 | * Fire-and-forget - errors are silently ignored. |
| 120 | */ |
| 121 | function trackUpdateFailed(errorMessage, version, context = {}) { |
| 122 | try { |
| 123 | const posthogConfig = getPostHogConfig() |
| 124 | if (!posthogConfig) { |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | const payload = JSON.stringify({ |
| 129 | api_key: posthogConfig.apiKey, |
| 130 | event: 'cli.update_freebuff_failed', |
| 131 | properties: { |
| 132 | distinct_id: `anonymous-${CONFIG.homeDir}`, |
| 133 | error: errorMessage, |
| 134 | version: version || 'unknown', |
| 135 | platform: process.platform, |
| 136 | arch: process.arch, |
| 137 | ...context, |
| 138 | }, |
| 139 | timestamp: new Date().toISOString(), |
| 140 | }) |
| 141 | |
| 142 | const parsedUrl = new URL(`${posthogConfig.host}/capture/`) |
| 143 | const isHttps = parsedUrl.protocol === 'https:' |
| 144 | const options = { |
| 145 | hostname: parsedUrl.hostname, |
| 146 | port: parsedUrl.port || (isHttps ? 443 : 80), |
| 147 | path: parsedUrl.pathname + parsedUrl.search, |
| 148 | method: 'POST', |
| 149 | headers: { |
| 150 | 'Content-Type': 'application/json', |
| 151 | 'Content-Length': Buffer.byteLength(payload), |
| 152 | }, |
| 153 | } |
| 154 | |
| 155 | const transport = isHttps ? https : http |
| 156 | const req = transport.request(options) |
| 157 | req.on('error', () => {}) |
| 158 | req.write(payload) |
| 159 | req.end() |
| 160 | } catch (e) { |
| 161 | // Silently ignore any tracking errors |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | const PLATFORM_TARGETS = { |
| 166 | 'linux-x64': `${packageName}-linux-x64.tar.gz`, |
no test coverage detected