Skip to content

Test discovery throws error when a workspace folder path is invalid #695

@adityasharad

Description

@adityasharad

Describe the bug
QL test discovery throws a user-facing error if one of the workspace folder entries in a multi-root workspace does not exist on the filesystem.

To Reproduce

  1. Create a VS Code .code-workspace file (or update an existing one) with the following entry:
    {
      "folders": [
        {
          "path": "/does/not/exist"
        }
    }
    
  2. Open that workspace file in VS Code with the CodeQL extension active.
  3. Activate the CodeQL extension, e.g. by clicking on the CodeQL sidebar panel. (Not necessary if the workspace has CodeQL-related source files or databases that would activate the extension.)
  4. The extension throws an error:
QL Test Discovery failed. Reason: Resolving tests failed: A fatal error occurred: /does/not/exist does not exist.
[2020-11-30 14:30:07] Exception caught at top level: /does/not/exist does not exist.
                      com.semmle.cli2.resolve.ResolveTestsCommand.executeJSON(ResolveTestsCommand.java:79)
                      com.semmle.cli2.resolve.ResolveTestsCommand.executeJSON(ResolveTestsCommand.java:33)
                      com.semmle.cli2.picocli.SimpleJsonSubcommand.executeInsistingOnJSON(SimpleJsonSubcommand.java:101)
                      com.semmle.cli2.picocli.SimpleJsonSubcommand.executeSubcommand(SimpleJsonSubcommand.java:77)
                      com.semmle.cli2.picocli.SubcommandCommon.executeWithParent(SubcommandCommon.java:414)
                      com.semmle.cli2.execute.CliServerCommand.lambda$executeSubcommand$0(CliServerCommand.java:67)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:201)
                      com.semmle.cli2.execute.CliServerCommand.executeSubcommand(CliServerCommand.java:67)
                      com.semmle.cli2.picocli.SubcommandCommon.call(SubcommandCommon.java:430)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:201)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:209)
                      com.semmle.cli2.CodeQL.main(CodeQL.java:91)

Expected behavior
Test discovery fails gracefully on non-existent workspace folders, and logs a warning without alerting the user.

Additional context
I ran into this for somewhat arcane reasons: I had migrated data between machines, and the filesystem paths to my home directory were different, making the absolute paths in the workspace file incorrect.
A user is more likely to run into this if they delete a directory (source or CodeQL database) from their filesystem without also removing it from the workspace.

Metadata

Metadata

Assignees

Labels

Complexity: LowA good task for newcomers to learn, or experienced team members to complete quickly.VSCodebugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions