sorcery icon indicating copy to clipboard operation
sorcery copied to clipboard

Install generator gives an error

Open Rinkana opened this issue 4 years ago • 7 comments

Configuration

  • Sorcery Version: master
  • Ruby Version: 2.7.2
  • Framework: Rails 6.1
  • Platform: Debian-slim (docker)

Expected Behavior

No errors during generation of new Sorcery setup.

Actual Behavior

When running rails generate sorcery:install --model=Admin::User i get the following:

      create  config/initializers/sorcery.rb
    generate  model Admin::User --skip-migration
       rails  generate model Admin::User --skip-migration
Running via Spring preloader in process 419
      invoke  active_record
      create    app/models/admin/user.rb
      create    app/models/admin.rb
      invoke    test_unit
      create      test/models/admin/user_test.rb
      create      test/fixtures/admin/users.yml
      insert  app/models/admin/user.rb
File unchanged! The supplied flag value not found!  app/models/admin/user.rb
      create  db/migrate/20201201102702_sorcery_core.rb

Steps to Reproduce

rails generate sorcery:install --model=Admin::User

Additional comments

The odd thing is is that the resulting model looks correct:

class Admin::User < ApplicationRecord
  authenticates_with_sorcery!
end

I've made a quick peek at the generator and i can't seem to find where the message comes from.

P.s. is there any info on a new release? I'd rather not point to the git repo and the master contains some useful fixes.

Rinkana avatar Dec 01 '20 10:12 Rinkana

Further debugging with byebug gives me something odd. It seems that it tries to add authenticate_with_sorcery! twice.

First time (success)

[217, 226] in /usr/local/bundle/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb
   217:     #   end
   218:     #
   219:     def inject_into_class(path, klass, *args, &block)
   220:       config = args.last.is_a?(Hash) ? args.pop : {}
   221:       config[:after] = /class #{klass}\n|class #{klass} .*\n/
=> 222:       insert_into_file(path, *(args << config), &block)
   223:     end
   224:
   225:     # Injects text right after the module definition. Since it depends on
   226:     # insert_into_file, it's reversible.
(byebug) path
"app/models/admin/user.rb"
(byebug) config
{:after=>/class Admin::User\n|class Admin::User .*\n/}
(byebug) args
["  authenticates_with_sorcery!\n"]
(byebug) n
      insert  app/models/admin/user.rb

Second time (fail)

[217, 226] in /usr/local/bundle/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb
   217:     #   end
   218:     #
   219:     def inject_into_class(path, klass, *args, &block)
   220:       config = args.last.is_a?(Hash) ? args.pop : {}
   221:       config[:after] = /class #{klass}\n|class #{klass} .*\n/
=> 222:       insert_into_file(path, *(args << config), &block)
   223:     end
   224:
   225:     # Injects text right after the module definition. Since it depends on
   226:     # insert_into_file, it's reversible.
(byebug) path
"app/models/admin/user.rb"
(byebug) config
{:after=>/class Admin::User\n|class Admin::User .*\n/}
(byebug) args
["  authenticates_with_sorcery!\n"]
(byebug) n
File unchanged! The supplied flag value not found!  app/models/admin/user.rb

Rinkana avatar Dec 01 '20 12:12 Rinkana

@Rinkana Is this still an issue with the latest release? (0.16.0)

If yes, could you do me a favor and try some previous releases to see when this issue was introduced? Narrowing down which version started having issues will make it easier for me to identify what change broke things.

joshbuker avatar Feb 19 '21 02:02 joshbuker

Going to assume this is fixed and close this out. If anyone is still have issues with it, please comment here and i'll reopen the issue.

joshbuker avatar Mar 09 '21 18:03 joshbuker

Configuration

Sorcery Version: 0.16.1 to 0.8.0 Ruby Version: 2.7.2 Framework: Rails 6.1 (gem 'rails', '~> 6.1.3', '>= 6.1.3.2') Platform: macOS 11.4

Expected Behavior

No errors during generation of new Sorcery setup.

Actual Behavior

Created new rails project for each version of sorcery:

rails new test0161
cd test0161

echo gem \'sorcery\', \'0.16.1\' >> Gemfile
bundle install
rails generate sorcery:install

With result:

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Running via Spring preloader in process 49001
      create  config/initializers/sorcery.rb
    generate  model User --skip-migration
       rails  generate model User --skip-migration 
Running via Spring preloader in process 49008
      invoke  active_record
      create    app/models/user.rb
      invoke    test_unit
      create      test/models/user_test.rb
      create      test/fixtures/users.yml
      insert  app/models/user.rb
File unchanged! The supplied flag value not found!  app/models/user.rb
      create  db/migrate/20210604182136_sorcery_core.rb

Additional comments

I tested: 0.16.1 0.16.0 0.15.1 0.15.0 0.14.0 0.13.0 0.12.0 0.11.0 0.10.0 0.9.0 0.8.0

The error was present for each version except 0.8.0 which had a dependency issue and didn't make it to rails generate sorcery:install.

Resolving dependencies...
Bundler could not find compatible versions for gem "rack":
  In snapshot (Gemfile.lock):
    rack (= 2.2.3)

  In Gemfile:
    rails (~> 6.1.3, >= 6.1.3.2) was resolved to 6.1.3.2, which depends on
      sprockets-rails (>= 2.0.0) was resolved to 3.2.2, which depends on
        actionpack (>= 4.0) was resolved to 6.1.3.2, which depends on
          rack (~> 2.0, >= 2.0.9)

    sorcery (= 0.8.0) was resolved to 0.8.0, which depends on
      oauth2 (~> 0.8.0) was resolved to 0.8.1, which depends on
        rack (~> 1.2)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

benmaher avatar Jun 04 '21 18:06 benmaher

Error message confirmed, although taking a quick glance at it suggests that all the files were generated properly, including the user model file which is the one that had an error.

@benmaher besides it spitting out an error, does it actually break at all?

joshbuker avatar Jun 04 '21 23:06 joshbuker

Looking into the error, it comes from Thor itself (the generator library) when an action doesn't actually change a file: https://www.rubydoc.info/github/rails/thor/master/Thor/Actions

I don't anticipate that I'll fix this in v0 for the following reasons:

  • This issue appears to have been present for the entire life of the Gem so far
  • The error message doesn't seem to actually affect the installation process in any way
  • I'll be redoing the generators significantly in v1 regardless, and will keep an eye out for linting/deprecation warnings

If someone else is interested in opening a PR with a fix, I'll take a look and try to merge it. Otherwise, this will have to wait for Sorcery v1 to be fixed.

joshbuker avatar Jun 04 '21 23:06 joshbuker

Error message confirmed, although taking a quick glance at it suggests that all the files were generated properly, including the user model file which is the one that had an error.

@benmaher besides it spitting out an error, does it actually break at all?

I'm not sure if it breaks as this is my first time using Sorcery. I'll comment if there is breakage.

benmaher avatar Jun 12 '21 13:06 benmaher