Skip to content

Compose error location#222

Open
maximeborges wants to merge 2 commits into
containers:mainfrom
maximeborges:compose-error-location
Open

Compose error location#222
maximeborges wants to merge 2 commits into
containers:mainfrom
maximeborges:compose-error-location

Conversation

@maximeborges

Copy link
Copy Markdown

Add location for error so it's easier to track the origin in long files, e.g. :

services.web.ports[0]: invalid type: integer `8080`, expected a set at line 5 column 9

instead of a bare invalid type: integer 8080, expected a set.

Previously every compose file was parsed through a serde_yaml::Value so we could expand << merge keys, but that discards source spans and left all schema errors location-less. from_yaml() now deserializes straight from the text, falling back to the Value + apply_merge path only when the file actually uses a merge key, for which we can't recover the error location properly anyway. Merge-key files produce identical output to before.

Applies on top of #219

Split the crate into a library (`src/lib.rs`) and a thin binary
(`src/main.rs`) so podlet can be used as a dependency. The library exposes
a small, string-based public API for in-memory compose -> Quadlet/Kubernetes
conversion, keeping internals private:

- `compose_to_files(yaml, ComposeOptions) -> Vec<GeneratedFile>`
- `Cli::try_into_generated_files()` for all subcommands
- `GeneratedFile`, `ComposeOptions`

Split `Compose::try_into_files` into an I/O part and a pure `into_files`
that takes an already-parsed `compose_spec::Compose`.

Patch `compose_spec` (k9withabone/compose_spec_rs#42) so absolute volume
paths validate on non-Unix targets.

Signed-off-by: Maxime Borges <contact@maximeborg.es>
Deserialize compose files directly from the source text so serde_yaml can
report the line, column, and field path of any error. Previously all parse
paths round-tripped through a serde_yaml::Value (needed to expand `<<` merge
keys), which discards source spans and left schema errors location-less
("invalid type: integer `8080`, expected a set").

The direct-parse path now handles the common case; it falls back to the
Value + apply_merge path only when the file actually uses merge keys, the one
case where a location cannot be recovered with serde_yaml.

Signed-off-by: Maxime Borges <contact@maximeborg.es>
@TheRealBecks

Copy link
Copy Markdown
Collaborator

@maximeborges You created a branch out of your branch for #219 and therefore this PR contains both features.

@maximeborges

Copy link
Copy Markdown
Author

I can move this one as a draft until #219 gets merged if you prefer; or if you don't want to go with #219, I can then edit this PR to make it work on the current model.

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