Skip to content

Error when buf.yaml dep is missing from buf.lock#4529

Open
stefanvanburen wants to merge 1 commit intomainfrom
svanburen/error-dep-missing-from-lock
Open

Error when buf.yaml dep is missing from buf.lock#4529
stefanvanburen wants to merge 1 commit intomainfrom
svanburen/error-dep-missing-from-lock

Conversation

@stefanvanburen
Copy link
Copy Markdown
Member

When a module is added to buf.yaml deps but buf dep update has not been
run, the module is absent from buf.lock entirely. Previously this caused
two bad outcomes depending on whether any proto files imported from the
missing dep:

  • If proto files imported from it: a confusing protoc-level "file not
    found" error with no mention of buf.lock or what to do.
  • If proto files did not yet import from it: MalformedDepsForWorkspace
    would flag it as MalformedDepTypeUnused, suggesting the user remove
    the dep — the opposite of the right advice.

Fix this by checking, during workspace construction, that every module
declared in buf.yaml deps has a corresponding entry in buf.lock. If any
are missing, return an actionable error immediately:

"buf.testing/acme/extension" declared in buf.yaml deps but not present
in buf.lock; run "buf dep update" to update the lock file

The check is added to both the v1 and v2 workspace construction paths
in workspace_provider.go and requires no network call — it is a pure
comparison of module full names between the two config files.

Two test cases are added: one where the missing dep is not yet used in
any proto file (previously: silent success with a misleading "unused"
warning), and one where the missing dep is actively imported (previously:
cryptic "file not found" from the compiler).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 7, 2026, 6:21 PM

@stefanvanburen stefanvanburen force-pushed the svanburen/error-dep-missing-from-lock branch from 4ec4076 to 51f821c Compare May 7, 2026 18:03
When a module is added to buf.yaml deps but buf dep update has not been
run, the module is absent from buf.lock entirely. Previously this caused
two bad outcomes depending on whether any proto files imported from the
missing dep:

- If proto files imported from it: a confusing protoc-level "file not
  found" error with no mention of buf.lock or what to do.
- If proto files did not yet import from it: MalformedDepsForWorkspace
  would flag it as MalformedDepTypeUnused, suggesting the user remove
  the dep — the opposite of the right advice.

Fix this by checking, during workspace construction, that every module
declared in buf.yaml deps has a corresponding entry in buf.lock. If any
are missing, return an actionable error immediately:

  "buf.testing/acme/extension" declared in buf.yaml deps but not present
  in buf.lock; run "buf dep update" to update the lock file

The check is added to both the v1 and v2 workspace construction paths
in workspace_provider.go and requires no network call — it is a pure
comparison of module full names between the two config files.

Two test cases are added: one where the missing dep is not yet used in
any proto file (previously: silent success with a misleading "unused"
warning), and one where the missing dep is actively imported (previously:
cryptic "file not found" from the compiler).
@stefanvanburen stefanvanburen force-pushed the svanburen/error-dep-missing-from-lock branch from 51f821c to 533fe37 Compare May 7, 2026 18:21
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.

1 participant