{"record":{"id":"7c13a55bb4012df1","repo":"Hmbown/CodeWhale","slug":"a-positive-pull-request-number-is-required","errorCode":null,"errorMessage":"A positive pull request number is required","messagePattern":"A positive pull request number is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/review_pr.rs","lineNumber":83,"sourceCode":"        [_, mode] => mode.len() == 6 && mode.bytes().all(|byte| matches!(byte, b'0'..=b'7')),\n        _ => false,\n    };\n    if !valid_fields {\n        return false;\n    }\n    let Some((old, new)) = fields[0].split_once(\"..\") else {\n        return false;\n    };\n    commit_id(old) && commit_id(new) && old.len() == new.len()\n}\n\nfn view_with(\n    number: u32,\n    repo: Option<&str>,\n    run: &mut impl FnMut(Program, &[String]) -> Result<String>,\n) -> Result<GhPullRequest> {\n    if number == 0 {\n        bail!(\"A positive pull request number is required\");\n    }\n    let mut args = pr_args(\"view\", number, repo);\n    args.extend([\"--json\".into(), VIEW_FIELDS.into()]);\n    let view: GhPullRequest = serde_json::from_str(&run(Program::Gh, &args)?)\n        .context(\"gh pr view returned incomplete PR metadata\")?;\n    if !commit_id(&view.base_sha) || !commit_id(&view.head_sha) {\n        bail!(\"gh pr view did not return exact base and head commit IDs\");\n    }\n    Ok(view)\n}\n\npub(crate) fn fetch_view(\n    number: u32,\n    repo: Option<&str>,\n    workspace: &Path,\n) -> Result<GhPullRequest> {\n    view_with(number, repo, &mut |program, args| {\n        run_command(workspace, program, args)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/review_pr.rs#L65-L101","documentation":"view_with in the PR review tool validates the pull request number before shelling out to `gh pr view`. A number of 0 (the u32 zero, typically an unset/default) is not a valid PR number, so it throws this error immediately rather than making a doomed gh call. It is raised in view_with, which is called by fetch_view and diff_with.","triggerScenarios":"Calling review_pr view/diff with number=0 — usually a default-initialized u32 that was never filled in from user input.","commonSituations":"Tool arguments not parsed from the user's request, leaving the default 0; a placeholder call in generated code; a UI passing an unselected PR number.","solutions":["Supply the actual positive PR number from the user's request or URL.","Parse and validate the PR number at the tool-argument boundary before invoking the tool.","If the number legitimately may be absent, check for 0 upstream and surface a clearer 'no PR selected' message."],"exampleFix":"// before\nreview_pr(number, repo).await?; // number defaults to 0\n// after\nlet number: u32 = args.number.unwrap_or_else(|| bail!(\"--pr number is required\"));\nreview_pr(number, repo).await?;","handlingStrategy":"validation","validationCode":"const prNumber = Number(args.number);\nif (!Number.isInteger(prNumber) || prNumber <= 0) {\n  throw new Error(\"a positive pull request number is required\");\n}","typeGuard":"function isValidPrNumber(n: unknown): n is number {\n  return typeof n === \"number\" && Number.isInteger(n) && n > 0;\n}","tryCatchPattern":null,"preventionTips":["Parse the PR number from user input or URL at the argument boundary; never rely on u32 defaults.","Reject unset/zero arguments with a clear 'no PR selected' message.","Validate tool arguments before invoking gh-backed operations."],"tags":["validation","github","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T06:17:15.046Z"}