Unable to load text file from global resource

I have a plain txt file as a global resource. Up to 0.122 I was able to resources.Get it and use its content as a string.

With 0.123.0 I get

ERROR failed to load data: failed to load data: "/home/user/website/assets/data/mystring.txt:1:1": unmarshal of format "" is not supported

Is this expected? How do I load a txt from now on?

Are you calling its content method? Please post your code.

Yes, I am using the Content method, exactly as the documentation suggests:

{{- $mail_text := resources.Get (printf "data/comment.%s.txt" .Site.Language.Lang) -}}
{{- $mail_body := $mail_text.Content -}}
{{- $mail_body = replace $mail_body " " "%20" -}}
{{- $mail_body = replace $mail_body "\n" "%0D%0A" -}}
{{- $mail_id := replace ( .RelPermalink | strings.TrimPrefix "/en" ) "/" "%2F" -}}
{{- $mailto_link := (printf `mailto:comment@evgenykuznetsov.org?In-Reply-To=%s&subject=%s&body=%s` ($mail_id | safeURL) ( (printf `Re: %s` ( .RelPermalink | strings.TrimPrefix "/en" )) | safeURL ) ( $mail_body | safeURL )) -}}
{{- $mailto := (printf `<a href="%s" title="%s">%s</a>` $mailto_link (T "send_comment_email") (T "by_email") | safeHTML) -}}

I am unable to reproduce the problem as described, so I must be missing something:

git clone --single-branch -b hugo-forum-topic-48365 https://github.com/jmooring/hugo-testing hugo-forum-topic-48365
cd hugo-forum-topic-48365

Expected console output from the above:

WARN  The content of the text file is:
WARN  This is the content of assets/data/comment.en.txt.


└── data/
    └── comment.en.txt


{{ warnf "The content of the text file is:" }}
{{ warnf (resources.Get (printf "data/comment.%s.txt" .Site.Language.Lang)).Content }}

Tested with hugo v0.123.0-3c8a471390

You are right, it seems to be unrelated.

I get the same error even if I remove this code, as long as I leave the txt file in place. I have even tried removing all the Unmarshal and unmarshal calls in my whole code, but the error keeps popping up.

Will try to investigate more tomorrow.

Where is the text file located? Did you place it, or a copy of it, in the data directory by mistake?

Or have you mounted assets/data to data, or something like that?

The text file is in assets/data, and there only (and that’s the path in the error message). And no, that path isn’t mounted elsewhere, at least as far as hugo config is aware.

I will dig deeper into this as soon as I have time.

I asked the previous questions because I can generate this error…

ERROR Rebuild failed: failed to load data: “/home/user/project/data/foo.txt:1:1”: unmarshal of format “” is not supported

…by placing any text file in the project’s data directory, and then calling {{ .Site.Data }} from any template.

Indeed, the call to .Site.Data is the one that triggers the error. However, I’m sure that assets/data is not mounted to data.

Also, moving the offending txts to assets (i.e. one level up) and changing the template respectively is a viable workaround.

What’s in the project/data folder?

Oh, there’s a mes.yaml that is used in date formatting. The YAML has month numbers with corresponding Russian names in proper declination, and I have a partial that looks like:

{{- if eq .ctx.Site.Language.Lang "ru" -}}{{ .date.Day }} {{ index .ctx.Site.Data.mes ( printf "%d" .date.Month ) }} {{ .date.Year }}{{- else -}}{{ .date.Format (.ctx.Site.Params.dateformat | default "Jan 02, 2006") }}{{- end -}}

I then call it somewhat like (partial "properdate" (dict "date" $date "ctx" $)) from various places where I need date properly formatted.

Can you share that file, or find someway of testing if there’s something about that file…

Here it is in full:

1: "января"
2: "февраля"
3: "марта"
4: "апреля"
5: "мая"
6: "июня"
7: "июля"
8: "августа"
9: "сентября"
10: "октября"
11: "ноября"
12: "декабря"

No, that’s fine. If you can share your repo (privately if you wish) that would help.

TBH, the theme is a mess that needs a heavy refactor I’ve been meaning to perform for a couple of years now, so I’m simply ashamed to do that.

1 Like

Now that you have access, you can git revert 39e7ead8a and have a repro, if you feel so inclined.

I found the problem. Will log an issue shortly.


1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

This was fixed in v0.123.6.

1 Like