Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cue/load: cannot load legacy published CUE modules #3219

Closed
myitcv opened this issue Jun 12, 2024 · 0 comments
Closed

cue/load: cannot load legacy published CUE modules #3219

myitcv opened this issue Jun 12, 2024 · 0 comments
Labels
modules Issues related to CUE modules and the experimental implementation NeedsInvestigation

Comments

@myitcv
Copy link
Member

myitcv commented Jun 12, 2024

What version of CUE are you using (cue version)?

$ cue version
v0.9.0

Does this issue reproduce with the latest release?

Yes

What did you do?

Consider the following, where the CUE module in the m directory is the result of downloading a module that has previously been published somewhere (e.g. an OCI registry). Note the module is missing a language.version: either because it was published prior to v0.8.0 (which introduced that field via v0.8.0-alpha.3) or because a tool using the Go API did not add such a line. The Go code below is in effect a simulation of a tool like Timoni (https://timoni.sh/) that uses the Go API, and consumes CUE modules that have been published someone, but not published via the mechanism that became the default in v0.9.0.

go mod tidy
go run .
cmp stdout stdout.golden

-- go.mod --
module mod.example

go 1.22.3

require cuelang.org/go v0.9.0

-- m/cue.mod/module.cue --
module: "mod.example/blah"

-- m/blah.cue --
package blah

blah: 42

-- main.go --
package main

import (
	"fmt"
	"log"

	"cuelang.org/go/cue/cuecontext"
	"cuelang.org/go/cue/load"
)

func main() {
	ctx := cuecontext.New()
	bis := load.Instances([]string{"."}, &load.Config{
		Dir: "./m",
	})
	v := ctx.BuildInstance(bis[0])
	if err := v.Err(); err != nil {
		log.Fatal(err)
	}
	fmt.Println(v)
}
-- stdout.golden --
{
	blah: 42
}

What did you expect to see?

The test to pass.

What did you see instead?

> go mod tidy
> go run .
[stderr]
main.go:18: no language version declared in module.cue
exit status 1

[exit status 1]
FAIL: /tmp/testscript3849746612/repro.txtar/script.txtar:2: unexpected go command failure

When we were considering the enforcing of language.version, we did not consider the case of pre-existing modules that have been published somewhere without a language.version. Instead our analysis focussed on consideration of those who had been using the modules experiment that started with the v0.8.0 alphas. This was a mistake. Because this Go code not working results in a breaking change for pre-existing modules of CUE that are published (which one should read as "and would need to be republished to add a language.version). This affects tools written against the Go API which themselves provide a means of downloading a published CUE module.

We are therefore proposing a fix via a flag for cue/load.Config that, when enabled, will enabled legacy modules without a language.version to be loaded.

@myitcv myitcv added NeedsInvestigation modules Issues related to CUE modules and the experimental implementation labels Jun 12, 2024
@myitcv myitcv moved this from Backlog to In progress in Modules Roadmap Jun 12, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Release v0.9 Jun 12, 2024
@myitcv myitcv moved this from Backlog to v0.9.1 in Release v0.9 Jun 12, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Modules Roadmap Jun 12, 2024
cueckoo pushed a commit that referenced this issue Jun 12, 2024
In some cases, we want to be able to accept legacy module files (module
files lacking a major version) because there's no easy way to fix them
by running `cue mod fix`. When running the cue command, `cue mod fix`
should always be a possibility - the problem exists principally when
using `cue/load` directly.

We don't want to make this the default, because interpreting module
files in this way is problematic, as it will discard fields that are
legitimately part of the non-legacy module schema.

So we add a boolean field that explicitly enables this behavior.

Fixes #3219.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I24d66eb680be3267adbe0a972705cc3414936362
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196156
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196230
Reviewed-by: Paul Jolly <paul@myitcv.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules Issues related to CUE modules and the experimental implementation NeedsInvestigation
Projects
Archived in project
Status: v0.9.1
Development

No branches or pull requests

1 participant