Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding error messages on exceptions for better diagnosis. #372

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export async function deactivate() {
await telemetry.clearReporter();
}

async function ensureErrorMessageOnException(callback: (...args: any[]) => any) {
try {
await callback();
} catch (err) {
vscode.window.showErrorMessage(err.message);
}
}

/**
* Activates components which require a ROS env.
*/
Expand Down Expand Up @@ -167,40 +175,64 @@ function activateEnvironment(context: vscode.ExtensionContext) {
// register plugin commands
subscriptions.push(
vscode.commands.registerCommand(Commands.CreateCatkinPackage, () => {
buildtool.BuildTool.createPackage(context);
ensureErrorMessageOnException(() => {
return buildtool.BuildTool.createPackage(context);
});
}),
vscode.commands.registerCommand(Commands.CreateTerminal, () => {
ros_utils.createTerminal(context);
ensureErrorMessageOnException(() => {
ros_utils.createTerminal(context);
});
}),
vscode.commands.registerCommand(Commands.GetDebugSettings, () => {
debug_utils.getDebugSettings(context);
ensureErrorMessageOnException(() => {
return debug_utils.getDebugSettings(context);
});
}),
vscode.commands.registerCommand(Commands.ShowCoreStatus, () => {
rosApi.showCoreMonitor();
ensureErrorMessageOnException(() => {
rosApi.showCoreMonitor();
});
}),
vscode.commands.registerCommand(Commands.StartRosCore, () => {
rosApi.startCore();
ensureErrorMessageOnException(() => {
rosApi.startCore();
});
}),
vscode.commands.registerCommand(Commands.TerminateRosCore, () => {
rosApi.stopCore();
ensureErrorMessageOnException(() => {
rosApi.stopCore();
});
}),
vscode.commands.registerCommand(Commands.UpdateCppProperties, () => {
ros_build_utils.updateCppProperties(context);
ensureErrorMessageOnException(() => {
return ros_build_utils.updateCppProperties(context);
});
}),
vscode.commands.registerCommand(Commands.UpdatePythonPath, () => {
ros_build_utils.updatePythonPath(context);
ensureErrorMessageOnException(() => {
ros_build_utils.updatePythonPath(context);
});
}),
vscode.commands.registerCommand(Commands.Rosrun, () => {
ros_cli.rosrun(context);
ensureErrorMessageOnException(() => {
return ros_cli.rosrun(context);
});
}),
vscode.commands.registerCommand(Commands.Roslaunch, () => {
ros_cli.roslaunch(context);
ensureErrorMessageOnException(() => {
return ros_cli.roslaunch(context);
});
}),
vscode.commands.registerCommand(Commands.Rosdep, () => {
rosApi.rosdep();
}),
vscode.commands.registerCommand(Commands.PreviewURDF, () => {
URDFPreviewManager.INSTANCE.preview(vscode.window.activeTextEditor.document.uri);
ensureErrorMessageOnException(() => {
rosApi.rosdep();
});
}),
vscode.commands.registerCommand(Commands.PreviewURDF, () => {
ensureErrorMessageOnException(() => {
URDFPreviewManager.INSTANCE.preview(vscode.window.activeTextEditor.document.uri);
});
}),
vscode.tasks.onDidEndTask((event: vscode.TaskEndEvent) => {
if (buildtool.isROSBuildTask(event.execution.task)) {
Expand Down
6 changes: 6 additions & 0 deletions src/ros/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function rosrun(context: vscode.ExtensionContext) {
reporter.sendTelemetryCommand(extension.Commands.Rosrun);

const terminal = await preparerosrun();
if (!terminal) {
return;
}
terminal.show();
}

Expand Down Expand Up @@ -41,6 +44,9 @@ export async function roslaunch(context: vscode.ExtensionContext) {
reporter.sendTelemetryCommand(extension.Commands.Roslaunch);

let terminal = await prepareroslaunch();
if (!terminal) {
return;
}
terminal.show();
}

Expand Down
4 changes: 2 additions & 2 deletions src/ros/ros2/ros2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export class ROS2 implements ros.ROSApi {
const packageBasePath = await packages[packageName]();
const command: string = (process.platform === "win32") ?
`where /r "${packageBasePath}" *launch.py` :
`find "${packageBasePath}" -type f -name *launch.py`;
`find -L "${packageBasePath}" -type f -name *launch.py`;

return new Promise((c, e) => child_process.exec(command, { env: this.env }, (err, out) => {
err ? e(err) : c(out.trim().split(os.EOL));
err ? e(new Error('No launch files are found.')) : c(out.trim().split(os.EOL));
}));
}

Expand Down