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

Workspace-level launch configurations crash if cwd is not specified #1057

Open
mathieuchopstm opened this issue Nov 7, 2024 · 0 comments
Open

Comments

@mathieuchopstm
Copy link

Describe the bug
If a launch configuration located in the VS Code workspace file (instead of the usual <folder>/.vscode/launch.json) does not specify cwd, attempting to launch a debug session will fail with a Cannot read property 'uri' of undefined error popup.

The bug seems to be located in resolveDebugConfigurationWithSubstitutedVariables:

public resolveDebugConfigurationWithSubstitutedVariables(
folder: vscode.WorkspaceFolder | undefined,
config: vscode.DebugConfiguration,
token?: vscode.CancellationToken
): vscode.ProviderResult<vscode.DebugConfiguration> {

The buggy statement appears to be the very first of the function:

let cwd = config.cwd || folder.uri.fsPath;

Note how the uri member is accessed without validity checks, despite it being vscode.WorkspaceFolder | undefined (folder?.uri.fsPath should probably have been used instead).

To Reproduce
Steps to reproduce the behavior:

  1. Create a VS Code Workspace
  2. Add a launch section in the .code-workspace file
  3. Create a cortex-debug launch configuration
  4. Making sure that cwd is not present in the launch configuration, attempt launch
  5. See issue: Cannot read property 'uri' of undefined
  6. Add cwd to launch configuration, attempt launch
  7. See that the debug session starts properly

Expected behavior

If cwd is not provided, rather than crashing, the extension should display an error message, as is done a few lines below the buggy code mentioned earlier.

config.cwd = cwd;
if (!fs.existsSync(cwd)) {
vscode.window.showWarningMessage(`Invalid "cwd": "${cwd}". Many operations can fail. Trying to continue`);
}

Screenshots

N/A

Environment:

  • Cortex-Debug: v1.12.1
  • OS: Linux Ubuntu 22.04 LTS
  • VSCode: 1.94.2
  • GDB Version: N/A
  • Compiler Toolchain Version: N/A

Additional context

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant