hasura/graphql-engine · error

cue extraction error: %w

Error message

cue extraction error: %w

What it means

Thrown by metadatautil.YAMLToJSON when the underlying CUE YAML parser (cueyaml.Extract) cannot parse the input YAML bytes into a CUE expression. It always wraps a lower-level parse error, so the %w detail names the exact line/column of the malformed YAML. It means the input is not syntactically valid YAML (or uses constructs the CUE extractor cannot represent).

Source

Thrown at cli/internal/metadatautil/yaml.go:215

	var (
		op        errors.Op = "metadatautil.GetIncludeTagFiles"
		filenames []string
	)

	_, err := resolveTags(map[string]string{baseDirectoryKey: baseDirectory}, node, &filenames)
	if err != nil {
		return filenames, errors.E(op, err)
	}

	return filenames, nil
}

func YAMLToJSON(yamlbs []byte) ([]byte, error) {
	var op errors.Op = "metadatautil.YAMLToJSON"

	cueExpr, err := cueyaml.Extract("", yamlbs)
	if err != nil {
		return nil, errors.E(op, fmt.Errorf("cue extraction error: %w", err))
	}

	cueNode, err := format.Node(cueExpr)
	if err != nil {
		return nil, errors.E(op, fmt.Errorf("cue formatting error: %w", err))
	}

	cueValue := cuecontext.New().CompileBytes(cueNode)

	jsonString, err := cuejson.Marshal(cueValue)
	if err != nil {
		return nil, errors.E(op, err)
	}

	return []byte(jsonString), nil
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Paste the YAML into a linter (yamllint or yamlchecker.com) and fix the syntax error named in the wrapped error message
  2. Run the CLI with verbose output to see the full wrapped cue extraction error including line/column
  3. Check for tabs used for indentation and replace with spaces
  4. Re-export the metadata from a known-good server (hasura metadata export) and reapply your changes incrementally

Example fix

// before (broken YAML):
// version: 3
// metadata:
// 	backend_configs:   # tab indentation
//     dataconnector: foo

// after (valid YAML, spaces only):
// version: 3
// metadata:
//   backend_configs:
//     dataconnector: foo
Defensive patterns

Strategy: validation

Validate before calling

import "gopkg.in/yaml.v3"

func validateYAML(data []byte) error {
	var v any
	return yaml.Unmarshal(data, &v)
}

Try / catch

if _, err := metadatautil.YAMLToJSON(data); err != nil {
	if strings.Contains(err.Error(), "cue extraction error") {
		// surface the wrapped parse detail to the user for the offending YAML
		return fmt.Errorf("invalid YAML metadata: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling YAMLToJSON with YAML containing bad indentation, unclosed quotes/brackets, tabs used for indentation, duplicate keys the CUE extractor rejects, or an empty/garbage []byte. Any caller pipeline (buildAddSourceBulkRequest, apply, ConvertMetadataToSDL, convertYamlToJsonWithIndent) that feeds an unvalidated metadata.yaml or user-supplied YAML hits this.

Common situations: A hand-edited metadata.yaml with a typo, a YAML file with Windows line endings mixed with tabs, a metadata file truncated by a failed git merge, or YAML aliases/anchors unsupported by the CUE extractor.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/736c12d1a81c0e18. Report an issue: GitHub.