Skip to content

paths: name the attribute in resolution errors, accept scalar additional contexts - #971

Merged
ndeloof merged 2 commits into
compose-spec:mainfrom
ndeloof:paths-error-attribute
Oct 25, 2026
Merged

ndeloof merged 2 commits into
compose-spec:mainfrom
ndeloof:paths-error-attribute

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

What this PR does, in one sentence

An error raised while resolving the paths of a project now names the attribute it comes from, and an additional build context written as a number no longer fails at all.

Context

When a value cannot be read as a path, the user gets a bare message that says nothing of where it comes from:

services:
  foo:
    build:
      context: 42      # without schema validation
unexpected type int

while every other step of the loading names the attribute (services[foo].secrets[0].mode ...). The same goes for a bind mount without a source, which did not even name the service.

One case is reachable with the schema validation too: additional_contexts is a list_or_dict, so the schema accepts a number or a boolean as the value of a mapping entry, and the model reads it as text. additional_contexts: {a: 1} was rejected with the bare unexpected type int, while additional_contexts: [a=1] loads.

What the PR brings

  • The errors of the resolution are prefixed, in the one place where the tree is walked, with the path of the attribute: services.foo.build.context: unexpected type int, services.foo.volumes.[]: invalid mount config for type "bind": field Source must not be empty. The entries of a list are written [], as in the errors of the transformations. The wrapped error is still available to errors.Is/As.
  • A number or a boolean as the value of an additional build context is resolved like the text it is written with, as in the list form (a: 1 gives <working dir>/1); a null one is left as it is, like build.ssh.
  • Compatibility: only the text of the errors changes, they are still errors of the same conditions.

🤖 Generated with Claude Code

A value that is not a path was reported as "unexpected type int", leaving the user to look for the number in the whole document. The error is now prefixed once, where the tree is walked, with the path of the attribute, as the errors of the other steps of the loading are.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…oolean

The schema accepts a number, a boolean or null as the value of a mapping of additional contexts, and the model reads them as text, but the resolution of paths rejected them. They are now resolved like the text they are written with, as in the list form.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review found no blocking issues in the focused implementation and regression coverage; tests were not executed.

No open issues 🎉

What changed in this PR

This PR improves Compose path-resolution errors by naming the affected attribute and makes scalar additional build contexts load consistently with their list-form equivalents.

Changes:

  • Prefix resolver errors with attribute paths while preserving wrapped errors.
  • Convert numeric and boolean additional contexts to strings, leaving null values unchanged.
  • Add regression coverage and update the expected bind-mount error.
File Description
paths/​resolve.go Adds attribute-aware error wrapping and routes additional contexts to their dedicated resolver.
paths/​resolve_test.go Tests scalar contexts and attribute paths in errors.
paths/​context.go Adds scalar conversion for additional build contexts.
loader/​tests/​build_test.go Adds loader coverage for scalar contexts and contextual errors.
loader/​loader_test.go Updates the expected bind-mount error text.

Review effort: Balanced

@ndeloof
ndeloof merged commit e44d4dc into compose-spec:main Oct 25, 2026
13 checks passed
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