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

too many arguments for format string, seemingly only when ruby -d #227

Open
zenspider opened this issue Jun 16, 2022 · 2 comments
Open

too many arguments for format string, seemingly only when ruby -d #227

zenspider opened this issue Jun 16, 2022 · 2 comments

Comments

@zenspider
Copy link

On rails boot we've got a bunch of stuff loading and normally everything works fine. HOWEVER, whenever I try to debug something by running rails boot via ruby -d (aka $DEBUG = true), rails bootstrap blows out thusly:

GEMS/moneta-1.5.1/lib/moneta/transformer.rb:359:in `%': too many arguments for format string (ArgumentError)
	from GEMS/moneta-1.5.1/lib/moneta/transformer.rb:359:in `block in compile_transformer'
	from GEMS/moneta-1.5.1/lib/moneta/transformer.rb:348:in `each'
	from GEMS/moneta-1.5.1/lib/moneta/transformer.rb:348:in `compile_transformer'
	from GEMS/moneta-1.5.1/lib/moneta/transformer.rb:65:in `compile'
	from GEMS/moneta-1.5.1/lib/moneta/transformer.rb:38:in `new'
	from GEMS/moneta-1.5.1/lib/moneta/builder.rb:65:in `new_proxy'
	from GEMS/moneta-1.5.1/lib/moneta/builder.rb:25:in `block in build'
	from GEMS/moneta-1.5.1/lib/moneta/builder.rb:23:in `each'
	from GEMS/moneta-1.5.1/lib/moneta/builder.rb:23:in `inject'
	from GEMS/moneta-1.5.1/lib/moneta/builder.rb:23:in `build'
	from GEMS/moneta-1.5.1/lib/moneta.rb:167:in `build'
	from GEMS/moneta-1.5.1/lib/moneta.rb:145:in `new'
... lots

I don't know if debug mode is changing the args going to that string format, or if debug mode is disabling something that's swallowing this exception and it is happening all the time.

I've doped the run to print out the format string:

# normal run:
{:CODE=>"::Marshal.dump(%s)"}
{:CODE=>"(options[:prefix] || @prefix)+%s"}
{:CODE=>"%s.sub(@prefix, '')"}
{:CODE=>"::Marshal.load(%s)"}
{:CODE=>"%s.start_with?(@prefix)"}
{:CODE=>"::Marshal.load(%s)"}
{:CODE=>"(::Marshal.load(key.start_with?(@prefix)) rescue '')"}
{:CODE=>"::Marshal.dump(%s)"}
{:CODE=>"::Marshal.load(%s)"}

vs:

# debug run:
{:CODE=>"::Marshal.dump(%s)"}
{:CODE=>"(options[:prefix] || @prefix)+%s"}
{:CODE=>"%s.sub(@prefix, '')"}
{:CODE=>"::Marshal.load(%s)"}
{:CODE=>"%s.start_with?(@prefix)"}
{:CODE=>"::Marshal.load(%s)"}
{:CODE=>"(::Marshal.load(key.start_with?(@prefix)) rescue '')"}

So I think since the last marshal line doesn't have %s on both sides, I suspect someone is swallowing that exception.

It LOOKS like this is being hit:

      def compile_prefix(name:, transformer:, value:)
        return unless [:encode, :serialize].include?(transformer[0])

        load_val, = compile_transformer([name], value, 1)
        "(#{load_val} rescue '')"
      end

and the result of that doesn't have a %s and gets passed to format.

@zenspider
Copy link
Author

Come to think of it... this just doesn't make sense:

::Marshal.load(key.start_with?(@prefix))

@asppsa
Copy link
Collaborator

asppsa commented Jun 17, 2022

Hey, thanks for the report. I've got covid right now, but will take a look at this when I can. If you work out how to fix this a PR would be most welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants