Skip to content

Commit

Permalink
* Use symlink follow when searching launch files. (#372)
Browse files Browse the repository at this point in the history
* Add error messages on exceptions for better diagnosis.
  • Loading branch information
seanyen authored Jan 13, 2021
1 parent b0b7777 commit 7459e44
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
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

0 comments on commit 7459e44

Please sign in to comment.