fix(xod-client-electron): make proper errors for different steps of upload process

This commit is contained in:
Kirill Shumilov
2018-10-18 19:21:47 +03:00
parent a76be3a471
commit 419dc11682
3 changed files with 73 additions and 45 deletions

View File

@@ -209,6 +209,30 @@ const patchFqbnWithOptions = board => {
)(selectedBoardOptions);
};
// =============================================================================
//
// Error wrappers
//
// =============================================================================
// :: Error -> RejectedPromise Error
const wrapCompileError = err =>
Promise.reject(
createError('COMPILE_TOOL_ERROR', {
message: err.message,
code: err.code,
})
);
// :: Error -> RejectedPromise Error
const wrapUploadError = err =>
Promise.reject(
createError('UPLOAD_TOOL_ERROR', {
message: err.message,
code: err.code,
})
);
// =============================================================================
//
// Handlers
@@ -369,18 +393,20 @@ const uploadThroughCloud = async (onProgress, cli, payload) => {
message: CODE_COMPILED,
tab: 'compiler',
});
const uploadLog = await cli.upload(
stdout =>
onProgress({
percentage: 60,
message: stdout,
tab: 'uploader',
}),
payload.port.comName,
payload.board.fqbn,
sketchName,
false
);
const uploadLog = await cli
.upload(
stdout =>
onProgress({
percentage: 60,
message: stdout,
tab: 'uploader',
}),
payload.port.comName,
payload.board.fqbn,
sketchName,
false
)
.catch(wrapUploadError);
onProgress({
percentage: 100,
message: '',
@@ -416,17 +442,19 @@ const uploadThroughUSB = async (onProgress, cli, payload) => {
tab: 'compiler',
});
const compileLog = await cli.compile(
stdout =>
onProgress({
percentage: 40,
message: stdout,
tab: 'compiler',
}),
payload.board.fqbn,
sketchName,
false
);
const compileLog = await cli
.compile(
stdout =>
onProgress({
percentage: 40,
message: stdout,
tab: 'compiler',
}),
payload.board.fqbn,
sketchName,
false
)
.catch(wrapCompileError);
onProgress({
percentage: 50,
@@ -434,18 +462,20 @@ const uploadThroughUSB = async (onProgress, cli, payload) => {
tab: 'uploader',
});
const uploadLog = await cli.upload(
stdout =>
onProgress({
percentage: 60,
message: stdout,
tab: 'uploader',
}),
payload.port.comName,
payload.board.fqbn,
sketchName,
false
);
const uploadLog = await cli
.upload(
stdout =>
onProgress({
percentage: 60,
message: stdout,
tab: 'uploader',
}),
payload.port.comName,
payload.board.fqbn,
sketchName,
false
)
.catch(wrapUploadError);
onProgress({
percentage: 100,
message: '',

View File

@@ -4,8 +4,14 @@ export default {
note: `Cloud compilation does not support ${boardName} yet.`,
solution: 'Try to compile it on your own computer',
}),
COMPILE_TOOL_ERROR: ({ message }) => ({
title: 'Compilation failed',
note: `Command ${message}`,
solution:
'The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.',
}),
UPLOAD_TOOL_ERROR: ({ message }) => ({
title: 'Upload tool exited with error',
title: 'Upload failed',
note: `Command ${message}`,
solution:
'Make sure the board is connected, the cable is working, the board model set correctly, the upload port belongs to the board, the board drivers are installed, the upload options (if any) match your board specs.',

View File

@@ -331,15 +331,7 @@ class App extends client.App {
board,
port,
}
).catch(err => {
console.error(err); // eslint-disable-line no-console
return Promise.reject(
createError('UPLOAD_TOOL_ERROR', {
message: err.message,
code: err.code,
})
);
})
)
)
.then(() => proc.success())
.then(() => {