prettier / plugin-ruby

Prettier Ruby Plugin
MIT License
1.45k stars 96 forks source link

Error: undefined method `value' for :call:Symbol #1434

Open chimpanstache opened 2 months ago

chimpanstache commented 2 months ago

Bumping into this error:

["INFO" - 11:01:30 AM] Formatting file:///Users/.../project/app/controllers/users_controller.rb
["INFO" - 11:01:30 AM] Using config file at /Users/.../project/.prettierrc
["INFO" - 11:01:30 AM] PrettierInstance:
{
  "modulePath": "/Users/.../project/node_modules/prettier/index.cjs",
  "importResolver": {},
  "callMethodResolvers": {},
  "currentCallMethodId": 15,
  "version": "3.2.5"
}
["INFO" - 11:01:30 AM] Using ignore file (if present) at /Users/.../project/.prettierignore
["INFO" - 11:01:30 AM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 11:01:30 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 11:01:30 AM] Prettier Options:
{
  "filepath": "/Users/.../project/app/controllers/users_controller.rb",
  "parser": "ruby",
  "plugins": [
    "/Users/.../project/node_modules/@prettier/plugin-ruby/src/plugin.js"
  ]
}
["ERROR" - 11:01:30 AM] Error formatting document.
["ERROR" - 11:01:30 AM] undefined method `value' for :call:Symbol
Error: undefined method `value' for :call:Symbol
    at Socket.<anonymous> (file:///Users/.../project/node_modules/@prettier/plugin-ruby/src/plugin.js:174:23)
    at Socket.emit (node:events:529:35)
    at endReadableNT (node:internal/streams/readable:1368:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
["INFO" - 11:01:30 AM] Formatting completed in 67ms.

here are my ruby and node versions:

nodejs          16.14.2         /Users/me/.tool-versions
ruby            3.2.3           /Users/me/.tool-versions

Same versions are used inside the project repository. Here are my Prettier and prettier-ruby versions inside my package.json file:

    "@prettier/plugin-ruby": "^3.2.2",
    "prettier": "2.7.1",

My .prettierrc file :

{
  "plugins": ["@prettier/plugin-ruby"]
}

My .prettierrc.json file :

 {
  "printWidth": 80
}
kddnewton commented 2 months ago

Hey @chimpanstache - any chance you could share your users_controller.rb file? If not, could you potentially try to format it while removing private content and get it down to a small reproduction? I can't do anything without a little more information unfortunately.

chimpanstache commented 2 months ago

Hey @kddnewton, there are only 2 contexts where value is appearing in that file, which are very same:

    result =
      estimate_duration.call(
        params: params,
      )
    if result.success?
      duration = result.value!

estimate_duration being an instance of this class:

class EstimateDuration
  include Wisper::Publisher
  include Dry::Monads[:result]
  extend Dry::Initializer

  def call(params:)
      ...

copilot explanation here if helpful:

Dry::Monads::Result can be either a Success or a Failure object. Both Success and Failure objects respond to the value! method.

In the case of a Success object, value! will return the value that the Success object is wrapping. However, if result is a Failure object, calling value! will raise an error.

Let me know if a larger code sample is necessary, thank you for helping me

kddnewton commented 2 months ago

value in this case is a method being called within syntax tree, it doesn't have to do with your file specifically. I imagine there's some place in your code that is calling something like:

foo.()

Do you see anything like that?

chimpanstache commented 2 months ago

Indeed, here it is:

    Dry::Matcher::ResultMatcher.(result) do |m|
      ...
kddnewton commented 2 months ago

Great! Now that we've found that, can you tell me the version of the syntax_tree gem that you have installed? That performs the actual formatting.

chimpanstache commented 2 months ago

Nice, there it is:

❯ gem list syntax_tree

*** LOCAL GEMS ***

syntax_tree (6.2.0)
syntax_tree-haml (4.0.3)
syntax_tree-rbs (1.0.0)
kddnewton commented 2 months ago

Is there anywhere else in that file that has calls like that? I'm still not quite able to reproduce here. (Thank you for your patience!)

kddnewton commented 2 months ago

Actually even better, could you run stree format path/to/file and give me the backtrace? That would be super helpful.

chimpanstache commented 2 months ago

No worries! No, it's the only place in that file. Here is the full backtrace :

❯ stree format app/controllers/users_controller.rb
undefined method `value' for :call:Symbol
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2779:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7614:in `block (2 levels) in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `block in if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7614:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7612:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9974:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `each'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2398:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2397:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4499:in `block in format_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `block in indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4497:in `format_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4415:in `block (2 levels) in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `block in if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4415:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4413:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7629:in `format_contents'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2791:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7614:in `block (2 levels) in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `block in if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:924:in `if_break'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7614:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:7612:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9986:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `each'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2398:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2397:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4207:in `block (2 levels) in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `block in indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4205:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:4175:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9986:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `each'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2398:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:2397:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:3383:in `block (2 levels) in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `block in indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:961:in `indent'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:3381:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `block in group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/prettier_print-1.2.1/lib/prettier_print.rb:1009:in `with_target'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:201:in `group'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:3378:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9974:in `block in format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `each'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:9970:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/formatter.rb:168:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/node.rb:8640:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree.rb:94:in `format_node'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree.rb:66:in `format'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/cli.rb:314:in `run'
/Users/elias/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/syntax_tree-6.2.0/lib/syntax_tree/cli.rb:671:in `block (2 levels) in process_queue'
kddnewton commented 2 months ago

Ah-ha! Found it. Thanks! That'll be fixed in the next release

chimpanstache commented 2 months ago

Fantastic! Thank you for your help. Looking forward the next release

kddnewton commented 2 months ago

In the meantime you can take the following steps:

  1. Change it to Dry::Matcher::ResultMatcher.call(result) do |m|
  2. Add a # stree-ignore comment before the line with the issue
  3. Ignore the whole file
chimpanstache commented 2 months ago

# stree-ignore for the win!