AaronC81 / parlour

A type signature generator, merger and parser system for Sorbet and Ruby 3/Steep
MIT License
91 stars 16 forks source link

TypeLoader#load_project call to generate file-table-json missing folder path parameter #122

Open mikeroher opened 3 years ago

mikeroher commented 3 years ago

Describe the bug TypeLoader#load_project fails due to changes in the Sorbet file-table-json generator.

The Sorbet file-table-json default parameter behaviour seems to have changed. Parlour's code changes into the user provided directory and calls the generator without passing in any folder path, under the assumption that the generator will use the current working directory if no path is provided. However, the generator now requires the folder path to be provided explicitly.

To Reproduce Call TypeLoader.load_project on any folder.

Expected behavior TypeLoader.load_project should return the RbiObjects.

Actual behavior

Traceback (most recent call last):
        6: from lib/gelato/parser.rb:10:in `<main>'
        5: from /Users/mikeroher/.rvm/gems/ruby-2.7.0/gems/sorbet-runtime-0.5.9057/lib/types/private/methods/_methods.rb:268:in `block in _on_method_added'
        4: from /Users/mikeroher/.rvm/gems/ruby-2.7.0/gems/sorbet-runtime-0.5.9057/lib/types/private/methods/call_validation.rb:161:in `validate_call'
        3: from /Users/mikeroher/.rvm/gems/ruby-2.7.0/gems/sorbet-runtime-0.5.9057/lib/types/private/methods/call_validation.rb:161:in `bind_call'
        2: from /Users/mikeroher/.rvm/gems/ruby-2.7.0/gems/parlour-6.0.1/lib/parlour/type_loader.rb:63:in `load_project'
        1: from /Users/mikeroher/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/json/common.rb:156:in `parse'
/Users/mikeroher/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/json/common.rb:156:in `parse': 783: unexpected token at '' (JSON::ParserError)

How to Fix The fix for this is to add the root folderpath as a parameter to the generator. This occurs on line 58 of type_loader.rb.

Current code:

stdin, stdout, stderr, wait_thr = T.unsafe(Open3).popen3(
        "bundle exec srb tc -p file-table-json",
        chdir: root
      )

Corrected code:

stdin, stdout, stderr, wait_thr = T.unsafe(Open3).popen3(
        "bundle exec srb tc -p file-table-json #{root}",
        chdir: root
      )
AaronC81 commented 3 years ago

Cheers for reporting! I'll aim to push out a fix for this soon, and try to put it behind a version gate so users of older Sorbets don't get errors when we pass an unexpected argument.

AaronC81 commented 3 years ago

@mikeroher I'm afraid I don't seem to be able to reproduce this on the latest Sorbet (0.5.9058) - what version of Sorbet are you using?

Either way, the form of -p file-table-json where an argument is passed seems to be valid on even relatively old versions of Sorbet, so if the no-argument form is causing problems somewhere, I see no harm in changing how we invoke it :)

mikeroher commented 3 years ago

@AaronC81 Ah strange, not sure what was causing it then! In any case, thank you for looking into it!!!

Fwiw, here's an excerpt of my Gemfile.lock:

    parlour (6.0.1)
      commander (~> 4.5)
      parser
      rainbow (~> 3.0)
      sorbet-runtime (>= 0.5)
    sorbet (0.5.9057)
      sorbet-static (= 0.5.9057)
    sorbet-runtime (0.5.9057)
    sorbet-static (0.5.9057-universal-darwin-14)