Hugo can’t catch errors. You could request a feature that makes it catchable, but I don’t know if that is useful enough for the majority.
Also, something might be off with your code, because unmarshalling “a,b,c” with a delimiter of “;” should result in [“a,b,c”] and no error, because not having the delimiter in it should not result in an error. It’s just one single element. The error states, that the format is not known. The format should be string or a resource. Are you sure those quotation marks are simple " and not some fancy typographic quotes in your code?
If possible, use a data format with rigid syntax. With CSV you have no idea if it contains a header row, if the fields are encapsulated, or which character is used to delimit the fields.
If you must use CSV, you could try to parse it yourself, but that will be very fragile. For example:
{{ $map := dict }}
{{ $data := "a,b,c" }}
{{ $delimiter := "," }}
{{ if in $data $delimiter }}
{{ $map = $data | transform.Unmarshal (dict "delimiter" $delimiter) }}
{{ else }}
{{ warnf "Data was not unmarshaled." }}
{{ end }}
Well, I guess its a dead end.
I don’t know the technical implications, but for my use case, it would be really needed to have some sort try/catch or isValid mechanism.
Thanks for the replies @jmooring !!