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

Problem with datasource reading yaml files with directory semantics #1333

Closed
Northburns opened this issue Mar 9, 2022 · 2 comments · Fixed by #1334
Closed

Problem with datasource reading yaml files with directory semantics #1333

Northburns opened this issue Mar 9, 2022 · 2 comments · Fixed by #1334
Assignees
Labels

Comments

@Northburns
Copy link

Northburns commented Mar 9, 2022

I have a template with a datasource which is a directory of yaml files. I followed the example from documentation "Datasources / Directory datasources". I have a problem getting this to work.

Minimal example to demonstrate, maybe it'll help in helping me understand what's going on 😊

# .gomplate.yaml
in: |-
  ** file.read **
  {{ file.Read "data/foo.yaml" | yaml }}
  ** ds **
  {{ ds "data" "foo.yaml" }}
  ** range ds **
  {{ range (ds "data") }}{{ ds "data" . }}
  {{ end }}
datasources:
  data: { url: data/ }
---
# data/foo.yaml
a: 1
b: "c"
> gomplate
** file.read **
map[a:1 b:c]
** ds **
map[a:1 b:c]
** range ds **
09:46:54 ERR  error="failed to render template <arg>: template: <arg>:6:26: executing \"<arg>\" at <ds \"data\" .>: error calling ds: Unable to unmarshal array a: 1\r\nb: \"c\"\r\n: yaml: unmarshal errors:\n  line 1: cannot unmarshal !!map into []interface {}"

I trust that you can see what is confusing me 😊 My Go is really rusty, but considering that the file is being unmarshalled to []interface {}, I guess this in file datasource.go (link to relevant line in tag v3.10.0) could be a place of interest:

func parseData(mimeType, s string) (out interface{}, err error) {
	// snip
	case yamlMimetype:
		out, err = YAML(s)
		if err != nil {
			// maybe it's a YAML array
			out, err = YAMLArray(s)
		}
	// snip
}

But I'm not very confident in this finding, I didn't take too much time to dig into this yet. I do have a small concern on this snippet ignoring the YAML function's err, though 🤷‍♂️

Please let me know if I can help in this issue in any way. I'll circumvent this for now using the file functions. Cheers!

@hairyhenderson
Copy link
Owner

Hmm... this seems to be a bug that's always existed... I'm a bit confused about why, but I'll dig into it.

I do have a small concern on this snippet ignoring the YAML function's err, though 🤷‍♂️

that's a fallback that's only hit if it fails to parse as YAML - from some quick debugging it doesn't seem it's hitting that code at all though... I'll update this issue when I find more.

@hairyhenderson hairyhenderson self-assigned this Mar 10, 2022
@hairyhenderson
Copy link
Owner

Ok, I think I have a handle on the issue, and a potential fix. Coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants