{"record":{"id":"9245a0ccadab6066","repo":"rust-lang/cargo","slug":"jobs-may-not-be-0","errorCode":null,"errorMessage":"jobs may not be 0","messagePattern":"jobs may not be 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_config.rs","lineNumber":90,"sourceCode":"        jobs: Option<JobsConfig>,\n        keep_going: bool,\n        requested_targets: &[String],\n        intent: UserIntent,\n    ) -> CargoResult<BuildConfig> {\n        let cfg = gctx.build_config()?;\n        let requested_kinds = CompileKind::from_requested_targets(gctx, requested_targets)?;\n        if jobs.is_some() && gctx.jobserver_from_env().is_some() {\n            gctx.shell().warn(\n                \"a `-j` argument was passed to Cargo but Cargo is \\\n                 also configured with an external jobserver in \\\n                 its environment, ignoring the `-j` parameter\",\n            )?;\n        }\n        let jobs = match jobs.or(cfg.jobs.clone()) {\n            None => default_parallelism()?,\n            Some(value) => match value {\n                JobsConfig::Integer(j) => match j {\n                    0 => anyhow::bail!(\"jobs may not be 0\"),\n                    j if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,\n                    j => j as u32,\n                },\n                JobsConfig::String(j) => match j.as_str() {\n                    \"default\" => default_parallelism()?,\n                    _ => {\n                        anyhow::bail!(format!(\n                            \"could not parse `{j}`. Number of parallel jobs should be `default` or a number.\"\n                        ))\n                    }\n                },\n            },\n        };\n\n        // If sbom flag is set, it requires the unstable feature\n        let sbom = match (cfg.sbom, gctx.cli_unstable().sbom) {\n            (Some(sbom), true) => sbom,\n            (Some(_), false) => {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/compiler/build_config.rs#L72-L108","documentation":"BuildConfig::new resolves the parallel job count. When the resolved jobs value is the integer 0 (from -j 0 or build.jobs = 0 in config), it bails immediately with 'jobs may not be 0' because zero parallelism is invalid. Negative values are treated as relative to default parallelism; the literal 0 is forbidden.","triggerScenarios":"Passing `-j 0` on the command line, or setting `jobs = 0` / `jobs = 0` under `[build]` in config (.cargo/config.toml). The match arm for 0 bails before any build starts.","commonSituations":"CI scripts computing `-j` from a variable that can be 0; config templates defaulting jobs to 0; env-driven job counts (e.g. -j$VAR with VAR unset->0 via shell).","solutions":["Use a positive integer: `-j 4` or omit -j to use default parallelism.","Use `-j default` (string) or a negative number (e.g. -j -1 reserves one core) for relative behavior.","Ensure scripts never pass 0: default the variable to a positive value or empty."],"exampleFix":"// before\ncargo build -j 0\n// after\ncargo build -j 4   # or omit -j","handlingStrategy":"validation","validationCode":"// Clamp jobs to >= 1 before invoking Cargo\nlet jobs = jobs_raw.max(1);\n// or guard the config value\nif let Some(0) = config.build.jobs { eprintln!(\"build.jobs must be > 0\"); }","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Never pass -j 0; default script variables to a positive integer or empty.","Use 'default' or omit -j to let Cargo pick parallelism."],"tags":["cargo","build","parallelism","jobs","configuration"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}