cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

Intermittent #FileInfo errors when parsing cue #1043

Closed tonyhb closed 3 years ago

tonyhb commented 3 years ago
v0.4.0

Does this issue reproduce with the latest release?

Yes

What did you do?

    cfg := &load.Config{
        Dir:        "/",
        ModuleRoot: "/",
        Overlay:    map[string]load.Source{},
    }
    cfg.Stdin = strings.NewReader(input)
    instances := load.Instances([]string{"-"}, cfg)

    if len(instances) != 1 {
        return nil, errors.Errorf("unsupported number of instances: %d", len(instances))
    }

    runtime := cuecontext.New()
    inst := runtime.BuildInstance(instances[0])
    if err := inst.Err(); err != nil {
        buf := &bytes.Buffer{}
        cueerrors.Print(buf, err, nil)
        return nil, errors.Wrap(ErrInvalidConfig, buf.String())
    }

Every 1 in ~8 times, Cue will error when validating it's own cue files:

#FileInfo.definitions: could not parse arguments: cannot convert non-concrete value bool:
    types.cue:26:2
#FileInfo.optional: could not parse arguments: cannot convert non-concrete value bool:
    types.cue:27:2
#FileInfo.const
raints: could not parse arguments: cannot convert non-concrete value bool:
    types.cue:28:2
#FileInfo.keepDefaults: could not parse arguments: cannot convert non-concrete value bool:
    types.cue:29:2
#FileInfo.incomplete: could not parse arguments: cannot convert
non-concrete value bool:
    types.cue:30:2
#FileInfo.imports: could not parse arguments: cannot convert non-concrete value bool:
    types.cue:31:2

What did you expect to see?

No errors, as the cue input is valid.

What did you see instead?

Errors parsing cue's own internal definitions.

tonyhb commented 3 years ago

This is fixable if I update the BuildFile generated within an instance as follows, prior to building the instance:

    instances[0].BuildFiles[0].Encoding = build.CUE
    instances[0].BuildFiles[0].Form = build.Schema
    instances[0].BuildFiles[0].Interpretation = ""

This is because Cue short circuits here: https://github.com/cuelang/cue/blob/master/internal/filetypes/filetypes.go#L77-L80

However, by default, Form is an empty string and so evaluating does not short circuit.

This isn't so much a fix - the race condition/bug exists somewhere when parsing cue's builtin, using gob encoding.

tonyhb commented 3 years ago

That was a lie, my bad! If I include packages, this transient error still exists. Packages are never included with the correct file builds to skip this short circuit: https://github.com/cuelang/cue/blob/master/internal/filetypes/filetypes.go#L77-L80.

Instead, I had to reimplement dependency resolution and file parsing to generate instances for each file (and their depencency).

cueckoo commented 3 years ago

This issue has been migrated to https://github.com/cue-lang/cue/issues/1043.

For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.