Skip to content

Commit 1c5087a

Browse files
committed
Convert rejected strings to the error objects
1 parent cc958ad commit 1c5087a

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

src/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function getVersion() {
6262
return reject(err.toString());
6363
}
6464
}
65-
return reject(stderr);
65+
return reject(new Error(stderr));
6666
}
6767
);
6868
});

src/home.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ async function _ensureServerStarted(options={}) {
143143
(code, stdout, stderr) => {
144144
if (code !== 0) {
145145
HTTP_PORT = 0;
146-
return reject(stderr);
146+
return reject(new Error(stderr));
147147
}
148148
}
149149
);
150150
tcpPortUsed.waitUntilUsed(HTTP_PORT, 500, SERVER_LAUNCH_TIMEOUT * 1000)
151151
.then(() => {
152152
resolve(true);
153153
}, (err) => {
154-
reject('Could not start PIO Home server: ' + err.toString());
154+
reject(new Error('Could not start PIO Home server: ' + err.toString()));
155155
});
156156
});
157157
}

src/installer/stages/platformio-core.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default class PlatformIOCoreStage extends BaseStage {
110110
if (fs.isFileSync(logFile)) {
111111
stderr = fs.readFileSync(logFile).toString();
112112
}
113-
return reject(`MSI Python2.7: ${stderr}`);
113+
return reject(new Error(`MSI Python2.7: ${stderr}`));
114114
}
115115
},
116116
{
@@ -155,7 +155,7 @@ export default class PlatformIOCoreStage extends BaseStage {
155155
if (code === 0) {
156156
return resolve(stdout);
157157
} else {
158-
return reject(`Conda Virtualenv: ${stderr}`);
158+
return reject(new Error(`Conda Virtualenv: ${stderr}`));
159159
}
160160
}
161161
);
@@ -174,7 +174,7 @@ export default class PlatformIOCoreStage extends BaseStage {
174174
if (code === 0) {
175175
return resolve(stdout);
176176
} else {
177-
return reject(`User's Virtualenv: ${stderr}`);
177+
return reject(new Error(`User's Virtualenv: ${stderr}`));
178178
}
179179
}
180180
);
@@ -189,7 +189,7 @@ export default class PlatformIOCoreStage extends BaseStage {
189189
if (code === 0) {
190190
return resolve(stdout);
191191
} else {
192-
return reject(`User's Virtualenv: ${stderr}`);
192+
return reject(new Error(`User's Virtualenv: ${stderr}`));
193193
}
194194
}
195195
);
@@ -231,7 +231,7 @@ export default class PlatformIOCoreStage extends BaseStage {
231231
if (stderr.includes('WindowsError: [Error 5]')) {
232232
userNotification = `If you use Antivirus, it can block PlatformIO Installer. Try to disable it for a while.\n\n${userNotification}`;
233233
}
234-
return reject(userNotification);
234+
return reject(new Error(userNotification));
235235
}
236236
}
237237
);
@@ -247,7 +247,7 @@ export default class PlatformIOCoreStage extends BaseStage {
247247
if (code === 0) {
248248
return resolve(stdout);
249249
} else {
250-
return reject(`Install Virtualenv globally: ${stderr}`);
250+
return reject(new Error(`Install Virtualenv globally: ${stderr}`));
251251
}
252252
}
253253
);
@@ -262,6 +262,7 @@ export default class PlatformIOCoreStage extends BaseStage {
262262
try {
263263
await this.createVirtualenvWithLocal(pythonExecutable);
264264
} catch (err) {
265+
misc.reportError(err);
265266
console.warn(err);
266267
try {
267268
await this.createVirtualenvWithDownload(pythonExecutable);
@@ -317,7 +318,7 @@ export default class PlatformIOCoreStage extends BaseStage {
317318
if (misc.IS_WINDOWS) {
318319
stderr += '\n If you have antivirus software in a system, try to disable it for a while.';
319320
}
320-
reject(`PIP: ${stderr}`);
321+
reject(new Error(`PIP: ${stderr}`));
321322
}
322323
});
323324
});

src/misc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,6 @@ export function reportError(err, tags=undefined) {
228228
Sentry.withScope(scope => {
229229
Object.entries(tags || {}).forEach(([key, value]) => scope.setTag(key, value));
230230
scope.setTag('caller', process.env.PLATFORMIO_CALLER);
231-
Sentry.captureException(err);
231+
Sentry.captureException(err instanceof Error ? err : new Error(err));
232232
});
233233
}

src/project/indexer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { runPIOCommand } from '../core';
4848
if (code === 0) {
4949
resolve();
5050
} else {
51-
reject(stderr);
51+
reject(new Error(stderr));
5252
}
5353
});
5454
});
@@ -122,7 +122,7 @@ import { runPIOCommand } from '../core';
122122
if (code === 0) {
123123
resolve(stdout.toString().trim().split(':'));
124124
} else {
125-
reject(stderr);
125+
reject(new Error(stderr));
126126
}
127127
},
128128
{

0 commit comments

Comments
 (0)