{"record":{"id":"e82ce14a96c03272","repo":"rust-lang/rust","slug":"no-compilation-artifacts","errorCode":null,"errorMessage":"No compilation artifacts","messagePattern":"No compilation artifacts","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/tools/rust-analyzer/editors/code/src/toolchain.ts","lineNumber":116,"sourceCode":"                (stderr) => log.error(stderr),\n                env,\n            );\n        } catch (err) {\n            log.error(`Cargo invocation has failed: ${err}`);\n            throw new Error(`Cargo invocation has failed: ${err}`, { cause: err });\n        }\n\n        return spec.filter?.(artifacts) ?? artifacts;\n    }\n\n    async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {\n        const artifacts = await this.getArtifacts(\n            Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),\n            runnableArgs.environment,\n        );\n\n        if (artifacts.length === 0) {\n            throw new Error(\"No compilation artifacts\");\n        } else if (artifacts.length > 1) {\n            throw new Error(\"Multiple compilation artifacts are not supported.\");\n        }\n\n        const artifact = unwrapUndefinable(artifacts[0]);\n        return artifact.fileName;\n    }\n\n    private async runCargo(\n        cargoArgs: string[],\n        onStdoutJson: (obj: CompilerMessage) => void,\n        onStderrString: (data: string) => void,\n        env?: Record<string, string>,\n    ): Promise<number> {\n        const path = await cargoPath(env);\n        return await new Promise((resolve, reject) => {\n            const cargo = cp.spawn(path, cargoArgs, {\n                stdio: [\"ignore\", \"pipe\", \"pipe\"],","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/editors/code/src/toolchain.ts#L98-L134","documentation":"Thrown by Cargo.executableFromArgs() at toolchain.ts:115-116 when getArtifacts() returns an empty array. getArtifacts() runs cargo with --message-format=json and collects CompilationArtifact entries only for messages where reason is 'compiler-artifact', an executable path is present, and (it's a non-buildscript binary OR a test profile). If zero messages match, no runnable executable was produced.","triggerScenarios":"executableFromArgs() is called when the user invokes a Run/Debug code lens. getArtifacts() returns []. This happens when: the target produces only a library (no bin/test artifact), the artifact filter for 'test'/'bench' specs removes all entries (line 64: result.filter filters by isTest but no test artifacts exist), cargo succeeded but emitted no 'compiler-artifact' message with an executable field, or the crate_type/kind didn't match the bin/test checks at lines 84-92.","commonSituations":"Clicking Run on a code lens for a library crate that has no binary or test target; running a 'bench' command on a crate without benchmarks; the cargo artifact JSON schema changed and the filter no longer matches; or trying to run an example/bench that produced a different artifact kind.","solutions":["Verify the target actually produces an executable: run 'cargo build --bin <name>' or 'cargo test --no-run' in the terminal and confirm a binary is emitted.","If running a test, ensure there are #[test] functions or a [[test]] target in Cargo.toml.","Check that the cargoArgs passed to executableFromArgs are correct (e.g. 'run' maps to 'build', 'test' needs test artifacts).","Update rust-analyzer to the latest version if the cargo JSON message format has changed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before calling executableFromArgs, verify the target produces an artifact.\n// Check Cargo.toml for [[bin]] or [[test]] targets matching the runnable.\nfunction targetProducesBinary(cargoArgs: string[]): boolean {\n  // 'run'/'build' requires a [[bin]] target; 'test' requires test artifacts\n  const cmd = cargoArgs[0];\n  if (cmd === 'run' || cmd === 'build') {\n    // verify a [[bin]] target exists — caller should parse Cargo.toml\n    return true; // placeholder for actual check\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const exe = await cargo.executableFromArgs(args);\n} catch (e) {\n  if (e.message === 'No compilation artifacts') {\n    vscode.window.showWarningMessage(\n      'This target does not produce a runnable binary. Use a [[bin]] or [[test]] target.'\n    );\n    return;\n  }\n  throw e;\n}","preventionTips":["Ensure the crate has a [[bin]] target before using the Run code lens.","For test runnables, confirm #[test] functions or [[test]] targets exist in Cargo.toml.","Check that the cargoArgs resolve to a target that emits a compiler-artifact with an executable field."],"tags":["rust-analyzer","cargo","artifacts","build","typescript"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}