Skip to content

Commit c0717f9

Browse files
committed
Report critical errors
1 parent f7b78c2 commit c0717f9

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
"escape": false,
1111
"navigator": false,
1212
"unescape": false,
13-
"window": false
13+
"window": false,
14+
"PACKAGE_VERSION": false
1415
},
1516
"plugins": [
1617
"import"

src/home.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import fs from 'fs-plus';
1313
import jsonrpc from 'jsonrpc-lite';
1414
import path from 'path';
1515
import qs from 'querystringify';
16+
import { reportError } from './misc';
1617
import request from 'request';
1718
import tcpPortUsed from 'tcp-port-used';
1819

@@ -123,6 +124,7 @@ export async function ensureServerStarted(options={}) {
123124
}
124125
attemptNums++;
125126
}
127+
reportError(lastError);
126128
throw lastError;
127129
}
128130

src/installer/stages/platformio-core.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
*/
88

99
import * as core from '../../core';
10-
11-
import { IS_WINDOWS, getPythonExecutable, runCommand } from '../../misc';
12-
import { PEPverToSemver, download, extractTarGz } from '../helpers';
10+
import * as helpers from '../helpers';
11+
import * as misc from '../../misc';
1312

1413
import BaseStage from './base';
1514
import fs from 'fs-plus';
@@ -39,7 +38,7 @@ export default class PlatformIOCoreStage extends BaseStage {
3938
async whereIsPython() {
4039
let status = this.params.pythonPrompt.STATUS_TRY_AGAIN;
4140
do {
42-
const pythonExecutable = await getPythonExecutable(this.params.useBuiltinPIOCore);
41+
const pythonExecutable = await misc.getPythonExecutable(this.params.useBuiltinPIOCore);
4342
if (pythonExecutable) {
4443
return pythonExecutable;
4544
}
@@ -68,7 +67,7 @@ export default class PlatformIOCoreStage extends BaseStage {
6867
// https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi
6968
const pythonArch = process.arch === 'x64' ? '.amd64' : '';
7069
const msiUrl = `https://www.python.org/ftp/python/${PlatformIOCoreStage.pythonVersion}/python-${PlatformIOCoreStage.pythonVersion}${pythonArch}.msi`;
71-
const msiInstaller = await download(
70+
const msiInstaller = await helpers.download(
7271
msiUrl,
7372
path.join(core.getCacheDir(), path.basename(msiUrl))
7473
);
@@ -90,7 +89,7 @@ export default class PlatformIOCoreStage extends BaseStage {
9089

9190
// install virtualenv
9291
return new Promise(resolve => {
93-
runCommand(
92+
misc.runCommand(
9493
'pip',
9594
['install', 'virtualenv'],
9695
() => resolve(pythonPath)
@@ -101,7 +100,7 @@ export default class PlatformIOCoreStage extends BaseStage {
101100
async installPythonFromWindowsMSI(msiInstaller, targetDir, administrative = false) {
102101
const logFile = path.join(core.getCacheDir(), 'python27msi.log');
103102
await new Promise((resolve, reject) => {
104-
runCommand(
103+
misc.runCommand(
105104
'msiexec.exe',
106105
[administrative ? '/a' : '/i', `"${msiInstaller}"`, '/qn', '/li', `"${logFile}"`, `TARGETDIR="${targetDir}"`],
107106
(code, stdout, stderr) => {
@@ -142,14 +141,14 @@ export default class PlatformIOCoreStage extends BaseStage {
142141

143142
isCondaInstalled() {
144143
return new Promise(resolve => {
145-
runCommand('conda', ['--version'], code => resolve(code === 0));
144+
misc.runCommand('conda', ['--version'], code => resolve(code === 0));
146145
});
147146
}
148147

149148
createVirtualenvWithConda() {
150149
this.cleanVirtualEnvDir();
151150
return new Promise((resolve, reject) => {
152-
runCommand(
151+
misc.runCommand(
153152
'conda',
154153
['create', '--yes', '--quiet', 'python=2', 'pip', '--prefix', core.getEnvDir()],
155154
(code, stdout, stderr) => {
@@ -168,7 +167,7 @@ export default class PlatformIOCoreStage extends BaseStage {
168167
this.cleanVirtualEnvDir();
169168
try {
170169
result = await new Promise((resolve, reject) => {
171-
runCommand(
170+
misc.runCommand(
172171
pythonExecutable,
173172
['-m', 'virtualenv', '-p', pythonExecutable, core.getEnvDir()],
174173
(code, stdout, stderr) => {
@@ -183,7 +182,7 @@ export default class PlatformIOCoreStage extends BaseStage {
183182
} catch (err) {
184183
this.cleanVirtualEnvDir();
185184
result = await new Promise((resolve, reject) => {
186-
runCommand(
185+
misc.runCommand(
187186
'virtualenv',
188187
['-p', pythonExecutable, core.getEnvDir()],
189188
(code, stdout, stderr) => {
@@ -201,22 +200,22 @@ export default class PlatformIOCoreStage extends BaseStage {
201200

202201
async createVirtualenvWithDownload(pythonExecutable) {
203202
this.cleanVirtualEnvDir();
204-
const archivePath = await download(
203+
const archivePath = await helpers.download(
205204
PlatformIOCoreStage.virtualenvUrl,
206205
path.join(core.getCacheDir(), 'virtualenv.tar.gz')
207206
);
208207
const tmpDir = tmp.dirSync({
209208
dir: core.getCacheDir(),
210209
unsafeCleanup: true
211210
}).name;
212-
const dstDir = await extractTarGz(archivePath, tmpDir);
211+
const dstDir = await helpers.extractTarGz(archivePath, tmpDir);
213212
const virtualenvScript = fs.listTreeSync(dstDir).find(
214213
item => path.basename(item) === 'virtualenv.py');
215214
if (!virtualenvScript) {
216215
throw new Error('Can not find virtualenv.py script');
217216
}
218217
return new Promise((resolve, reject) => {
219-
runCommand(
218+
misc.runCommand(
220219
pythonExecutable,
221220
[virtualenvScript, core.getEnvDir()],
222221
(code, stdout, stderr) => {
@@ -241,7 +240,7 @@ export default class PlatformIOCoreStage extends BaseStage {
241240

242241
installVirtualenvPackage(pythonExecutable) {
243242
return new Promise((resolve, reject) => {
244-
runCommand(
243+
misc.runCommand(
245244
pythonExecutable,
246245
['-m', 'pip', 'install', 'virtualenv'],
247246
(code, stdout, stderr) => {
@@ -267,11 +266,13 @@ export default class PlatformIOCoreStage extends BaseStage {
267266
try {
268267
await this.createVirtualenvWithDownload(pythonExecutable);
269268
} catch (err) {
269+
misc.reportError(err);
270270
console.warn(err);
271271
try {
272272
await this.installVirtualenvPackage(pythonExecutable);
273273
await this.createVirtualenvWithLocal(pythonExecutable);
274274
} catch (err) {
275+
misc.reportError(err);
275276
console.warn(err);
276277
throw new Error('Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv');
277278
}
@@ -281,12 +282,12 @@ export default class PlatformIOCoreStage extends BaseStage {
281282

282283
async upgradePIP(pythonExecutable) {
283284
// we use manual downloading to resolve SSL issue with old `pip`
284-
const pipArchive = await download(
285+
const pipArchive = await helpers.download(
285286
PlatformIOCoreStage.pipUrl,
286287
path.join(core.getCacheDir(), path.basename(PlatformIOCoreStage.pipUrl))
287288
);
288289
return new Promise(resolve => {
289-
runCommand(pythonExecutable, ['-m', 'pip', 'install', '-U', pipArchive], (code, stdout, stderr) => {
290+
misc.runCommand(pythonExecutable, ['-m', 'pip', 'install', '-U', pipArchive], (code, stdout, stderr) => {
290291
if (code !== 0) {
291292
console.warn(stderr);
292293
}
@@ -309,11 +310,11 @@ export default class PlatformIOCoreStage extends BaseStage {
309310
args.push('platformio');
310311
}
311312
return new Promise((resolve, reject) => {
312-
runCommand(pythonExecutable, args, (code, stdout, stderr) => {
313+
misc.runCommand(pythonExecutable, args, (code, stdout, stderr) => {
313314
if (code === 0) {
314315
resolve(stdout);
315316
} else {
316-
if (IS_WINDOWS) {
317+
if (misc.IS_WINDOWS) {
317318
stderr += '\n If you have antivirus software in a system, try to disable it for a while.';
318319
}
319320
reject(`PIP: ${stderr}`);
@@ -373,7 +374,7 @@ export default class PlatformIOCoreStage extends BaseStage {
373374
}
374375

375376
async check() {
376-
const coreVersion = PEPverToSemver(await core.getVersion());
377+
const coreVersion = helpers.PEPverToSemver(await core.getVersion());
377378

378379
if (this.params.useBuiltinPIOCore) {
379380
if (!fs.isDirectorySync(core.getEnvBinDir())) {

src/misc.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import { getCacheDir , getEnvBinDir, getEnvDir, getHomeDir } from './core';
1010

1111
import fs from 'fs-plus';
12-
import path from 'path';
1312
import os from 'os';
13+
import path from 'path';
1414
import qs from 'querystringify';
1515
import request from 'request';
1616
import spawn from 'cross-spawn';
@@ -210,15 +210,15 @@ export function disposeSubscriptions(subscriptions) {
210210
}
211211
}
212212

213-
export function reportError(err, tags) {
213+
export function reportError(err, tags=undefined) {
214214
// Hook for Webpack: include dependencies for Sentry
215-
require("@sentry/core");
216-
require("@sentry/hub");
217-
require("@sentry/minimal");
218-
require("@sentry/types");
219-
require("@sentry/utils");
215+
require('@sentry/core');
216+
require('@sentry/hub');
217+
require('@sentry/minimal');
218+
require('@sentry/types');
219+
require('@sentry/utils');
220220
// End hook for Webpack
221-
const Sentry = require("@sentry/node");
221+
const Sentry = require('@sentry/node');
222222
Sentry.init({
223223
dsn: 'https://2c83f4457e234ddf9b3476d079fb8334@sentry.io/1309781',
224224
release: PACKAGE_VERSION,
@@ -227,6 +227,7 @@ export function reportError(err, tags) {
227227
});
228228
Sentry.withScope(scope => {
229229
Object.entries(tags || {}).forEach(([key, value]) => scope.setTag(key, value));
230+
scope.setTag('caller', process.env.PLATFORMIO_CALLER);
230231
Sentry.captureException(err);
231232
});
232233
}

0 commit comments

Comments
 (0)