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

error at blank record in data set: "no implicit conversion of nil into String (TypeError)" #118

Open
mtlx03 opened this issue Apr 23, 2022 · 1 comment
Labels
fixed? Issue fixed, waiting for confirmation

Comments

@mtlx03
Copy link

mtlx03 commented Apr 23, 2022

Hi, your plugin is a lifesaver. I'm new to Jekyll and Ruby so please pardon my ignorance.

I'm getting this error, and failed output:

(eval):1:in `+': no implicit conversion of nil into String (TypeError)

when the script encounters a blank record (deliberate) in the csv data file:

biz | zip
ABC | 99835
XYZ | 99840
FGH | 99623
VBN |
ASD | 99833

config.yml looks like:

page_gen:
  - data: 'my-data'
    template: 'default'
    name_expr: record['biz'] + "_" + record['zip']
    title: 'biz'
    dir: 'misc'
    debug: yes

I'd like the filename to be biz and (optionally, only if it exists) _zip.

Here's more of the debug output:

debug (datapage-gen) Record read:
>> {"biz"=>"VBN", "zip"=>nil}       
debug (datapage-gen) Configuration variables:
>> index_files: false
>> dir: misc
>> page_data_prefix:
>> name:
>> name_expr: record['biz'] + "_" + record['zip']
>> title: zip
>> title_expr:
>> template: default
>> extension: html
(eval):1:in `+': no implicit conversion of nil into String (TypeError)

Many thanks for having a look!

@avillafiorita
Copy link
Owner

Hi,
the issue is with the zip field, which is empty in the record before the last one: this causes name_expr to fail, since record['zip'] returns nil and nil cannot be concatenated to a string.

Try changing name_expr with something like:

 name_expr: "#{record['biz']}_#{record['zip']}"

or

 name_expr: (record['biz'] || "") + "_" + (record['zip'] || "")

Let me know if it works!

@avillafiorita avillafiorita added the fixed? Issue fixed, waiting for confirmation label Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed? Issue fixed, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants