github / codeql-cli-binaries

Binaries for the CodeQL CLI
Other
752 stars 112 forks source link

The output location should both be a directory and not be directory #48

Open lorenzleutgeb opened 4 years ago

lorenzleutgeb commented 4 years ago
> mkdir out
> codeql query run -d java-database -o out overrides.ql
A fatal error occurred: [redacted]/out is a directory.
> rmdir out
> codeql query run -d java-database -o out overrides.ql
A fatal error occurred: The output location [redacted]/out is not a directory, so only a single query can be executed.

overrides.ql is taken from https://help.semmle.com/QL/learn-ql/java/annotations.html

import java

from Method overriding, Method overridden
where overriding.overrides(overridden) and
    not overriding.getAnAnnotation() instanceof OverrideAnnotation
select overriding, "Method overrides another method, but does not have an @Override annotation."
> codeql version
CodeQL command-line toolchain.
Version: 2.2.3.
Copyright (C) 2019-2020 GitHub, Inc.
Unpacked in: /nix/store/s5zfg5vzrfrfc3mqyh3g0r4r6mpqc2g1-codeql-2.2.3/codeql
   Analysis results depend critically on separately distributed query and
   extractor modules. To list modules that are visible to the toolchain,
   use 'codeql resolve qlpacks' and 'codeql resolve languages'.
> uname -a
Linux nixos 5.9.1 #1-NixOS SMP Sat Oct 17 06:31:22 UTC 2020 x86_64 GNU/Linux
> nixos-version
20.09.1500.edb26126d98 (Nightingale)
hmakholm commented 4 years ago

I can't reproduce the "only a single query can be executed" error here. It looks very weird; that message should only produced when there is more than one non-option argument, or the name specified does not in in .ql.

Would you be able to supply the log files produced by giving a --logdir some-directory too?

As a workaround while we figure out what's going on, you might have better luck with codeql database run-queries which does want a directory.

lorenzleutgeb commented 4 years ago

OK, so this might be because the input file name did not match *.ql. I have to admit that I cheated when submitting the bug, the file was called something else on my machine. Nevertheless, the output is very confusing:

> touch x
> mkdir out
> codeql query run --logdir=logs -d java-database -o out x
A fatal error occurred: [redacted]/out is a directory.
> rmdir out
> codeql query run --logdir=logs -d java-database -o out x 
A fatal error occurred: The output location [redacted]/out is not a directory, so only a single query can be executed.

First Run, with out

[2020-11-03 19:29:56] This is codeql query run --logdir=logs -d java-database -o out x
[2020-11-03 19:29:56] Exception caught at top level: [redacted]/out is a directory.
                      com.semmle.cli2.ql.RunCommand.executeSubcommand(RunCommand.java:84)
                      com.semmle.cli2.picocli.SubcommandCommon.call(SubcommandCommon.java:407)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:182)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:190)
                      com.semmle.cli2.CodeQL.main(CodeQL.java:89)

Second Run, without out

[2020-11-03 19:30:07] This is codeql query run --logdir=logs -d java-database -o out x
[2020-11-03 19:30:07] Calling plumbing command: codeql resolve ram --format=json
[2020-11-03 19:30:07] Plumbing command codeql resolve ram completed:
                      [
                        "-J-Xmx3973M",
                        "--off-heap-ram=3973"
                      ]
[2020-11-03 19:30:07] Spawning plumbing command: execute queries -J-Xmx3973M --off-heap-ram=3973 --verbosity=progress --logdir=[redacted]/logs --ml-model-path= --native-library-path= --warnings=show --output=[redacted]/out -- [redacted]/java-database/db-java [redacted]/x
[2020-11-03 19:30:08] [ERROR] Spawned process exited abnormally (code 2; tried to run: [/nix/store/s5zfg5vzrfrfc3mqyh3g0r4r6mpqc2g1-codeql-2.2.3/codeql/tools/linux64/java/bin/java, -Xmx3973M, -Djava.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib, -cp, /nix/store/s5zfg5vzrfrfc3mqyh3g0r4r6mpqc2g1-codeql-2.2.3/codeql/tools/codeql.jar, com.semmle.cli2.CodeQL, execute, queries, -J-Xmx3973M, --off-heap-ram=3973, --verbosity=progress, --logdir=[redacted]/logs, --ml-model-path=, --native-library-path=, --warnings=show, --output=[redacted]/out, --, [redacted]/java-database/db-java, [redacted]/x])
[2020-11-03 19:30:08] Plumbing command codeql execute queries terminated with status 2.
[2020-11-03 19:30:08] Exiting with code 2
[2020-11-03 19:30:08] This is codeql execute queries -J-Xmx3973M --off-heap-ram=3973 --verbosity=progress --logdir=[redacted]/logs --ml-model-path= --native-library-path= --warnings=show --output=[redacted]/out -- [redacted]/java-database/db-java [redacted]/x
[2020-11-03 19:30:08] Exception caught at top level: The output location [redacted]/out is not a directory, so only a single query can be executed.
                      com.semmle.cli2.execute.ExecuteQueriesCommand.executeSubcommand(ExecuteQueriesCommand.java:110)
                      com.semmle.cli2.picocli.SubcommandCommon.call(SubcommandCommon.java:407)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:182)
                      com.semmle.cli2.picocli.SubcommandMaker.runMain(SubcommandMaker.java:190)
                      com.semmle.cli2.CodeQL.main(CodeQL.java:89)
hmakholm commented 4 years ago

Yes, that would explain it.

The CLI uses file extensions to distinguish between whether the file being named is a query (*.ql) or a query suite definition (*.qls). Even though codeql query run cannot run query suites, the execution eventually gets handled by general shared code that can.

We will consider ways to improve the error message to be less confusing in future releases. Thanks for the report.