Visitar URL original
Use script-aware lock mismatch diagnostics by zaniebot · Pull Request #232 · zaniebot/uv · GitHub
Skip to content

Use script-aware lock mismatch diagnostics - #232

Closed
zaniebot wants to merge 1 commit into
mainfrom
zb/bughunt200/136-script-lock-diagnostics
Closed

zaniebot wants to merge 1 commit into
mainfrom
zb/bughunt200/136-script-lock-diagnostics

Conversation

@zaniebot

@zaniebot zaniebot commented Jul 14, 2026 •

Copy link
Copy Markdown
Owner

Stale script-lock diagnostics refer to uv.lock and suggest uv lock, directing users to update the wrong file. Render the actual script lock and script-aware repair command; quote paths safely so spaces and shell metacharacters cannot make the hint unusable. This completes the target-specific guidance after script-lock support in uv#18832 and lock hints in uv#20219.

Promoted upstream: astral-sh/uv#20439.

Comment thread crates/uv/src/commands/project/mod.rs Outdated
Comment on lines +403 to +408
Self::LockMismatch(_, _, _, lockfile) if lockfile != "uv.lock" => {
let script = lockfile.strip_suffix(".lock").unwrap_or(lockfile);
uv_errors::Hints::from(format!(
"To update the lockfile, run `uv lock --script {script}`."
))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird. It suggests we shouldn't pass through lockfile as a string but rather information which identifies if it's a script and the script path?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which is maybe the Target or something?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I replaced the string inference with an owned lock-target kind carrying the script path, and use that path to construct a safely quoted --script hint. Added coverage for a nested script with spaces in its filename.

@zaniebot
zaniebot force-pushed the zb/bughunt200/136-script-lock-diagnostics branch from e8e1463 to 10ace64 Compare July 15, 2026 15:46
Comment on lines +28 to +33
/// An owned lock target for use in diagnostics.
#[derive(Debug, Clone)]
pub(crate) enum LockTargetKind {
Workspace,
Script(PathBuf),
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have a concept for this elsewhere?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the existing targets. LockTarget and the similar TreeJsonTarget both borrow the workspace/script, while this error is propagated through anyhow and must own the script path. The other project targets own full parsed projects/scripts and are command-specific. I kept the small owned lock-target kind here to avoid cloning those structures or widening the lock API.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure to have that be in the /// doc comment referencing LockTarget plz

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed on the current branch head: the LockTargetKind doc comment now references LockTarget and explains that lock-mismatch diagnostics cannot retain its borrowed target.

@zanieb
zanieb marked this pull request as ready for review July 15, 2026 15:50
@zanieb zanieb closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants