开发者

trying to find a file/line for: .(eval):289: warning: don't put space before argument parentheses

So, I get this warning when I'm running my tests in ruby/RoR

.(eval):289: warni开发者_如何转开发ng: don't put space before argument parentheses

I've checked every where (but obvoiusly not) and I can't find the origin of this error.

The above error just pops up inbetween the unit tests ...

Can someone clue me in onto how to find the location of this error?


The file and line number are contained in the backtrace. However, in your case, the warning is inside a string being evaled at runtime. Which means there is no file. (Actually, the eval method does take optional arguments for the file name and line number that should be displayed in a backtrace, but in this case whoever wrote the code in question unfortunately forgot to pass those arguments.)

I fear that you have no other choice than to manually examine every single call to eval in your entire codebase, and that includes Rails, your testing framework, your entire application, your tests, your plugins, your helpers, the ruby standard library, ...

Of course, you should be aware that the problem might not be obvious as in

eval 'foo (bar, baz)'

It could also be something like

def foo(*args)
  puts args.join
end

bar = 'Hello'
baz = 'World'

foostr = 'foo'                        # in one file
barstr = 'bar'                        # in another file in a different directory
bazstr = 'baz'                        # in another file in a different directory
argstr = "(#{barstr}, #{bazstr})"     # in yet another file
$,     = ' '                          # in some third-party plugin
str    = [foostr, argstr].join        # in a fourth file
eval str                              # somewhere else entirely
eval str, binding, __FILE__, __LINE__ # this is how it *should* be done

Note the difference between the two warning messages: the first one reads exactly like the one you posted, but the second one has the filename instead of (eval) and the line number inside the file instead of the line number inside the eval string.

By the way: the line number 289 in the warning message is the line number inside the evald string! In other words: somewhere in your application there is a string being evald, which is at least 289 lines long! (Actually, it is more likely that this done not in your application but rather in Rails. The Rails router used to be a particularly bad offender, I don't know if this is still the case.)


It sounds to me that there is a rule which forbids a space between a function name and the parentheses enclosing the arguments of the function.

In many languages this would be considered a permissible stylistic variation.

Is the eval mentioned in the warning message, the 'function' being complained about?

Does the number 289 mean anything as a line number?

Could you search your source files for a parenthesis preceded by a space?

Incidentally, the message says warning. What happens if you ignore it?


If it's happening in between the unit tests it might be in a setup or teardown method. Try searching for eval or try reducing the code you are running until the error goes away. Then you'll know where to look (the code you just removed).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜