Skip to content

Source maps#773

Merged
cpuguy83 merged 9 commits intoproject-dalec:mainfrom
cpuguy83:source_maps
Oct 17, 2025
Merged

Source maps#773
cpuguy83 merged 9 commits intoproject-dalec:mainfrom
cpuguy83:source_maps

Conversation

@cpuguy83
Copy link
Collaborator

@cpuguy83 cpuguy83 commented Oct 1, 2025

Add source maps to errors and LLB definitions

This makes it so when an error is returned the error carries with it
details about where in the spec file the error occurred.

To accomplish, each object that wants to provide detailed location info
needs to implement a custom UnmarshalYAML method which takes the
location from the yaml AST and stores it so it can be retrieved later as
needed.

Future work here would involve providing even more detailed source
mappings in some cases (e.g. a source type that has a "digest" field,
which is a type we don't own so can't just store the mapping to it
easily like we do for owned types).

Closes #756 (includes the changes from there already, and some additional ones).

@cpuguy83 cpuguy83 requested a review from a team as a code owner October 1, 2025 22:43
Copilot AI review requested due to automatic review settings October 1, 2025 22:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive source map support to error handling and LLB definitions in the dalec system. When errors occur, they now carry detailed location information about where in the spec file the error occurred, making debugging much easier for users.

  • Implements custom UnmarshalYAML methods for types that need location tracking
  • Updates package dependency handling to use maps instead of string slices for better type safety and source mapping
  • Refactors test infrastructure to use a dedicated test runner with structured error reporting

Reviewed Changes

Copilot reviewed 54 out of 55 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sourcemap.go New file implementing source map tracking and location constraint utilities
load.go Refactored YAML loading to support source map context and AST-based unmarshaling
tests.go Added source map tracking to test structures and error reporting
deps.go Changed package dependencies from string slices to maps with constraint support
spec.go Updated core spec types to support source mapping during unmarshaling
Multiple source files Added UnmarshalYAML methods and source map fields to various source types
Multiple target files Updated build systems to use new dependency structure and source location tracking
frontend/test_runner.go Complete rewrite to use structured test runner with better error attribution

@cpuguy83 cpuguy83 force-pushed the source_maps branch 14 times, most recently from b74aa9c to 225e1e8 Compare October 3, 2025 23:15
@cpuguy83 cpuguy83 mentioned this pull request Oct 6, 2025
@@ -130,6 +122,9 @@ func (w *controlWrapper) depends(buf *strings.Builder, depsSpec *dalec.PackageDe
needsClone = false
}

Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: extra whitespace that makes it not match the similar block below

Suggested change

if !slices.ContainsFunc(deps, hasRust) {
return llb.Scratch(), errors.New("spec contains go modules but does not have golang in build deps")
if !slices.ContainsFunc(pkgNames, hasRust) {
return llb.Scratch(), errors.New("spec contains cargo homes but does not have rust in build deps")
Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow, nice catch lol

This makes it so the test evaluator runs *inside* the container.
This means we don't need to do crazy things with stdio routing nor do we
need to go through the buidlkit API for every file request.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This makes it so when an error is returned the error carries with it
details about where in the spec file the error occurred.

To accomplish, each object that wants to provide detailed location info
needs to implement a custom UnmarshalYAML method which takes the
location from the yaml AST and stores it so it can be retrieved later as
needed.

Future work here would involve providing even more detailed source
mappings in some cases (e.g. a source type that has a "digest" field,
which is a type we don't own so can't just store the mapping to it
easily like we do for owned types).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Really this shouldn't be needed since we aren't unmarshalling json here
(ever), but its easier to fix this than to figure out something for the
linter.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Some cases are just logic cleanups, others are fixing potential panics
after some recent changes to the underlying type.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 added this to the v0.18 milestone Oct 17, 2025
@cpuguy83 cpuguy83 merged commit 79c72e6 into project-dalec:main Oct 17, 2025
22 checks passed
@cpuguy83 cpuguy83 deleted the source_maps branch October 17, 2025 19:46
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.

3 participants