ruby-syntax-tree / syntax_tree

Interact with the Ruby syntax tree

Home Page:https://ruby-syntax-tree.github.io/syntax_tree/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

private method `format' called for nil:NilClass

gtrias opened this issue · comments

Hello,

Firstly, I'd like to express my appreciation for your outstanding work on this library. It's greatly appreciated!

We've integrated it into our Continuous Integration (CI) checks and have come across occasional type errors. Interestingly, I'm unable to reproduce this issue on my end. I've attempted to run the same code with the identical command on my local machine, and everything works flawlessly. Our CI environments aren't configured in any particularly unusual manner either.

Here's the warning we're encountering:

Running the command in this way:

echo "components/timeoff/spec/services/timeoff/working_hours_for_day_calculators/french_calendar_days_spec.rb" | xargs bundle exec stree check
[warn] components/timeoff/spec/services/timeoff/working_hours_for_day_calculators/french_calendar_days_spec.rb
private method `format' called for nil:NilClass
/runner/_work/foo/backend/vendor/bundle/ruby/2.7.0/gems/syntax_tree-6.1.1/lib/syntax_tree.rb:93:in `format_node'
/runner/_work/foo/backend/vendor/bundle/ruby/2.7.0/gems/syntax_tree-6.1.1/lib/syntax_tree.rb:65:in `format'
/runner/_work/foo/backend/vendor/bundle/ruby/2.7.0/gems/syntax_tree-6.1.1/lib/syntax_tree/cli.rb:136:in `run'
/runner/_work/foo/backend/vendor/bundle/ruby/2.7.0/gems/syntax_tree-6.1.1/lib/syntax_tree/cli.rb:671:in `block (2 levels) in process_queue'

Despite my best efforts, I'm currently unable to pinpoint the cause of this issue. Could you possibly shed some light on what might be the root cause?

If I manage to reproduce this bug consistently, I'll make sure to report it here. Thanks in advance for your assistance!

Could you add the contents of the file it fails to parse?

Sorry I can't share the file contents. But I think I've found the cause of the problem! It seems that all failing files have something in common. All them have emojis inside. I'm going to check what LANG env var we have set in CI and try to change it to see if it changes something.

I confirm the problem was related to utf8 characters such as emojis. We ended up fixing it by proper installing and setting the locales in our Github Actions Runner docker images:

# Set the locale
RUN sudo sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && sudo locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
commented

Thanks for this, for us it was random characters for example É

adding the following to our dockerfile resolved the issue

ENV LC_ALL="C.UTF-8"
ENV LANG="C.UTF-8"