{"record":{"id":"ac8d5957548578db","repo":"pnpm/pnpm","slug":"deprecateerror","errorCode":null,"errorMessage":"{DeprecateError}","messagePattern":"\\{DeprecateError\\}","errorType":"exception","errorClass":"DeprecateError","httpStatus":null,"severity":"error","filePath":"pnpm/crates/cli/src/cli_args/unpublish/mutation.rs","lineNumber":38,"sourceCode":"pub(super) struct MutationRequest<'a> {\n    pub(super) method: &'a Method,\n    pub(super) url: &'a str,\n    pub(super) json_body: Option<&'a str>,\n}\n\n/// An HTTP-level failure of an unpublish mutation, handed to the\n/// [`OtpSession`]. Only the [`Otp`](Self::Otp) arm is a challenge it acts on;\n/// the rest propagate.\n#[derive(Debug, Display, Error, Diagnostic)]\nenum UnpublishHttpError {\n    #[display(\"the registry requested a one-time password\")]\n    Otp {\n        #[error(not(source))]\n        challenge: OtpChallenge,\n    },\n\n    #[diagnostic(transparent)]\n    Registry(#[error(not(source))] DeprecateError),\n}\n\nimpl OtpError for UnpublishHttpError {\n    fn as_otp_challenge(&self) -> Option<OtpChallenge> {\n        match self {\n            UnpublishHttpError::Otp { challenge } => Some(challenge.clone()),\n            UnpublishHttpError::Registry(_) => None,\n        }\n    }\n}\n\n/// Send one mutation through the OTP session: the first attempt carries any\n/// configured `--otp`; a 401 OTP challenge drives the interactive flow and\n/// the request is retried with the obtained password, while any other 401 is\n/// a plain authentication failure. Every other status is returned for the\n/// caller to classify.\npub(super) async fn send_mutation<Sys: UnpublishHost, Reporter: self::Reporter>(\n    mutation: &mut MutationContext<'_>,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/pnpm/pnpm/blob/e45f0332229b094d61f2ecad114a166e338c0d61/pnpm/crates/cli/src/cli_args/unpublish/mutation.rs#L20-L56","documentation":"UnpublishHttpError::Registry wraps a DeprecateError raised during an unpublish mutation (PUT to the package document / tarball DELETE). It is #[diagnostic(transparent)], so the message is the inner DeprecateError from `registry_operation_failed`/`write_error_for_status`, e.g. a registry rejection of the unpublish. The OTP session deliberately does not treat this arm as a one-time-password challenge; send_mutation unwraps it so the registry error is shown once without OTP-wrapper narration.","triggerScenarios":"Produced when the registry returns a non-2xx status for an unpublish mutation that is not an OTP challenge: 403 for packages published >72h ago without proper authorization, 404 for a nonexistent package/version, 401 for bad credentials, or 5xx registry failures.","commonSituations":"Trying to unpublish a version outside the registry's unpublish window, missing or expired npm token, unpublishing a package version that does not exist, or a registry policy forbidding unpublish of a package that others depend on.","solutions":["Check the status in the message: 404 - verify the package name and version exist; 403 - you likely lack rights or the version is past the unpublish window; use `pnpm deprecate` instead.","For 401, refresh your auth: `pnpm login` or update the token in .npmrc.","If unpublish is blocked by policy, deprecate the version (`pnpm deprecate <pkg>@<version> \"message\"`) rather than removing it.","For 5xx, retry later."],"exampleFix":"// before\npnpm unpublish my-pkg@1.2.3   // 403: outside unpublish window\n// after\npnpm deprecate my-pkg@1.2.3 \"broken release, use 1.2.4\"","handlingStrategy":"try-catch","validationCode":"// Confirm the version exists and you are authorized before unpublishing\nlet who = std::process::Command::new(\"pnpm\").arg(\"whoami\").output()?;\nif !who.status.success() { return Err(\"not logged in to the registry\".into()); }\nlet view = std::process::Command::new(\"pnpm\")\n    .args([\"view\", &format!(\"{pkg}@{version}\", ), \"version\"]).output()?;\nif !view.status.success() { return Err(format!(\"{pkg}@{version} not found; nothing to unpublish\".into()); }","typeGuard":null,"tryCatchPattern":"// Branch on status before deciding between retry, deprecate fallback, or abort\nmatch run_unpublish() {\n    Err(e) if msg_contains(&e, \"403\") => {\n        eprintln!(\"outside unpublish window or forbidden; falling back to `pnpm deprecate`\");\n        run_deprecate(pkg, version)?;\n    }\n    Err(e) if msg_contains(&e, \"401\") => Err(\"re-authenticate: pnpm login\".into()),\n    Err(e) => Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Prefer `pnpm deprecate` when the version may be past the registry's unpublish window.","Refresh the auth token before scripted unpublish/deprecate runs.","Confirm the exact version with `pnpm view <pkg>@<version>` before unpublishing.","Remember unpublish requires ownership rights on the package."],"tags":["registry","http","unpublish","cli"],"backgroundTag":"http-error-response","analyzedSha":"e45f0332229b094d61f2ecad114a166e338c0d61","analyzedAt":"2026-09-22T05:07:20.233Z","contentChangedAt":"2026-09-22T05:07:20.233Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}