@@ -187355,16 +187355,21 @@ function registerCLITool(server, definition) {
187355187355 positionalArgs = [...positionalArgs, ...files];
187356187356 }
187357187357 if (file && name.startsWith("codeql_bqrs_")) {
187358- let cleanFile = Array.isArray(file) ? String(file[0]) : String(file);
187358+ let cleanFile = Array.isArray(file) ? file.length > 0 ? String(file[0]) : "" : String(file);
187359187359 if (cleanFile.startsWith("[") && cleanFile.endsWith("]")) {
187360187360 try {
187361187361 const parsed = JSON.parse(cleanFile);
187362187362 if (Array.isArray(parsed) && parsed.length > 0) {
187363187363 cleanFile = String(parsed[0]);
187364+ } else {
187365+ cleanFile = "";
187364187366 }
187365187367 } catch {
187366187368 }
187367187369 }
187370+ if (!cleanFile) {
187371+ throw new Error('The "file" parameter for BQRS tools must be a non-empty string path to a .bqrs file.');
187372+ }
187368187373 positionalArgs = [...positionalArgs, cleanFile];
187369187374 }
187370187375 if (qlref && name === "codeql_resolve_qlref") {
@@ -187498,26 +187503,30 @@ function registerCLITool(server, definition) {
187498187503 case "codeql_bqrs_interpret":
187499187504 if (options.database) {
187500187505 const dbPath = resolveDatabasePath(options.database);
187501- const srcZipPath = join10(dbPath, "src.zip");
187502- const srcDirPath = join10(dbPath, "src");
187503- if (existsSync6(srcZipPath)) {
187504- options["source-archive"] = srcZipPath;
187505- } else if (existsSync6(srcDirPath)) {
187506- options["source-archive"] = srcDirPath;
187507- } else {
187508- delete options.database;
187509- throw new Error(
187510- `CodeQL database at "${dbPath}" does not contain a source archive (expected "src.zip" file or "src" directory).`
187511- );
187506+ if (!options["source-archive"]) {
187507+ const srcZipPath = join10(dbPath, "src.zip");
187508+ const srcDirPath = join10(dbPath, "src");
187509+ if (existsSync6(srcZipPath)) {
187510+ options["source-archive"] = srcZipPath;
187511+ } else if (existsSync6(srcDirPath)) {
187512+ options["source-archive"] = srcDirPath;
187513+ } else {
187514+ delete options.database;
187515+ throw new Error(
187516+ `CodeQL database at "${dbPath}" does not contain a source archive (expected "src.zip" file or "src" directory).`
187517+ );
187518+ }
187512187519 }
187513- const dbYmlPath = join10(dbPath, "codeql-database.yml");
187514- try {
187515- const dbYml = readFileSync7(dbYmlPath, "utf8");
187516- const dbMeta = load(dbYml);
187517- if (dbMeta?.sourceLocationPrefix && typeof dbMeta.sourceLocationPrefix === "string") {
187518- options["source-location-prefix"] = dbMeta.sourceLocationPrefix;
187520+ if (!options["source-location-prefix"]) {
187521+ const dbYmlPath = join10(dbPath, "codeql-database.yml");
187522+ try {
187523+ const dbYml = readFileSync7(dbYmlPath, "utf8");
187524+ const dbMeta = load(dbYml);
187525+ if (dbMeta?.sourceLocationPrefix && typeof dbMeta.sourceLocationPrefix === "string") {
187526+ options["source-location-prefix"] = dbMeta.sourceLocationPrefix;
187527+ }
187528+ } catch {
187519187529 }
187520- } catch {
187521187530 }
187522187531 delete options.database;
187523187532 }
0 commit comments