Error message "failed to read data" from csv even it is working fine

Following the solution i gave here Accessing hugo’s template variable inside Javascript files? I now read data directly from CSV.

It is working just fine. But …

  1. I have this error when I rebuild the site (or live reload too) : Building sites … ERROR Failed to read data from data1.csv/data1.csv: Data not supported for extension 'csv'
  2. The CSV file (/data/data1.csv) is read and processed perfectly, even if message seems to misread the path.
  3. If I juste change some small thing on the CSV file, the error message disappear (no more error) the first time, and still builds perfectly. I change nothing to hugo, templates, or whatever.
  4. The second time I change a small thing on CSV file error messages is back again (and still builds fine)
  5. Now I just change a small thing on a template (for example) and let the CSV untouched. It build without error.
  6. Until I change the CSV, etc… etc …

The code for readng the CSV file is on the previous link and quite simple.

Inside a shortcode, I use passed parameter :slight_smile:

{{ if .Get "csvfile" }}
    {{ $csvURL := .Get "csvfile" }}
    {{ $csv := getCSV "," $csvURL }}
bla bla
{{ end }}

Is it me, a real bug in the build/analysis process or just some strange behaviour on error message ??

Anyway I just ignore this message and all seems fine.

I’m useless @ Golang, but I downloaded the hugo source and looked around to see if I can find some tip about the cause …

The error occurs in site.go,

  • when function readData() fails and error message doesn’t take CSV files in account (only yaml,json,toml are in the switch case)
  • when function handleDataFile() can’t readData() and report a wrong file name : r.Path() is wrong

My Golang skills stops me there. May be this can help some Golang guru to find what I think is a (rare) bug, even it doesn’t seems to have a bad effect on the process.

Update : In fact, it seems that build fails every 2 changes.
So I need to change csv and some html so it builds correctly.

To be clear :

  • Sometimes the error message is here but it does builds correctly
  • and sometimes the error message is here and it doesn’t build correctly.

It’s hard for me to say what’s going on here since I don’t follow you completely.

But if an error with reading a CSV file happens every so often, then that might also be caused by Hugo caching the CSV file or performing a fast render.

You can disable both of those options with the --ignoreCache and --disableFastRender command flags for the hugo and hugo server commands. That may help to troubleshoot what causes the error message.

Thanks @Jura for looking.

I think I narrowed the problem.

  1. I just add a csv file unknown.csv wich is a copy of a working csv file.
  2. I don’t reference or call or whatever this new file. (verified by searching thru my code)
  3. Hugo sees a change in /data/ & rebuilds the site.
  4. I get this same error, even if I do nothing with the file:
Change detected, rebuilding site
2018-03-02 20:29:19.793 +0100
Data changed "/Users/me/Documents/Git/chart/data/unknown.csv": CREATE
Data changed "/Users/me/Documents/Git/chart/data/stats-contrat-1.1.csv": RENAME
ERROR 2018/03/02 20:29:19 Failed to read data from data1.csv/data1.csv: Data not supported for extension 'csv'
ERROR 2018/03/02 20:29:19 Failed to read data from data2.csv/data2.csv: Data not supported for extension 'csv'
ERROR 2018/03/02 20:29:19 Failed to read data from stats-contrat-1.csv/stats-contrat-1.csv: Data not supported for extension 'csv'
ERROR 2018/03/02 20:29:19 Failed to read data from unknown.csv/unknown.csv: Data not supported for extension 'csv'
Total in 97 ms
INFO 2018/03/02 20:29:21 Received System Events: ["/Users/me/Documents/Git/chart/data/unknown.csv": CHMOD]
  • The data1.csv / data2.csv / stats-contrat-1.csv are good CSV files and treated well by some other parts of my code.
  • Seems something is reading/doingwhatever the data folder, and thinking those files are wrong.

Oh … I was already invoquing hugo like that:

hugo server --disableFastRender --ignoreCache  --verbose

The problem you have is that Hugo does not support CSV files in the /data folder. So, if you remove that file, the ERROR will go away.

We do, however, support CSV files via the getCSV function:

But you need to store the CSV file in some other folder (not /data).


Ahhhhhhhhhhhhhhhh Thanks a lot @bep. Will do that.

But is is strange because it seems to me that belong to data for builing my site. Anyway, thanks a lot for the light …

1 Like

Something was changed recently. Because with earlier versions there was no problem witth a CSV file in data. I now have the same problem with a csv-file which rendered until version 0.38. with the cited error message. Now with 0.38 hugo stops rendering after the error.

When I put the csv file in static or content I get the error

error calling getCSV: Cannot find separator ; in CSV.

I only changed the location. No changes in the file or the code that calls the file.