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

Loader wants to manage directory which is already managed #53

Closed
jcoyne opened this issue May 23, 2019 · 3 comments
Closed

Loader wants to manage directory which is already managed #53

jcoyne opened this issue May 23, 2019 · 3 comments

Comments

@jcoyne
Copy link
Contributor

jcoyne commented May 23, 2019

I have two gems. One called dor-services which knows nothing of zeitwerk and one called dor-services-client. The latter is a dependency of the former. The latter does use zeitwerk. When I run tests for dor-services I now get:

Failure/Error: require 'dor/services/client'

Zeitwerk::Error:
  loader

  #<Zeitwerk::Loader:0x00007fdd1e44f2e8
   @autoloaded_dirs=[],
   @autoloads={},
   @eager_load_exclusions=#<Set: {}>,
   @eager_loaded=false,
   @ignored=#<Set: {}>,
   @ignored_paths=#<Set: {}>,
   @inflector=#<DorServicesClientInflector:0x00007fdd1e44ef78>,
   @initialized_at=2019-05-23 15:53:38 -0500,
   @lazy_subdirs={},
   @logger=nil,
   @mutex=#<Thread::Mutex:0x00007fdd1e44efc8>,
   @mutex2=#<Thread::Mutex:0x00007fdd1e44efa0>,
   @preloads=[],
   @reloading_enabled=false,
   @root_dirs={},
   @setup=false,
   @shadowed_files=#<Set: {}>,
   @tag="1157b8",
   @to_unload={}>


  wants to manage directory /Users/jcoyne85/workspace/sul-dlss/dor-services/lib, which is already managed by

  #<Zeitwerk::Loader:0x00007fdd1d887c30
   @autoloaded_dirs=[],
   @autoloads=
    {"/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/tasks"=>
      [Object, :Tasks],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/indexers"=>
      [Dor, :Indexers],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/exceptions.rb"=>
      [Dor, :Exceptions],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/utils"=>
      [Dor, :Utils],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/models"=>
      [Dor, :Models],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/workflow"=>
      [Dor, :Workflow],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/release_tags.rb"=>
      [Dor, :ReleaseTags],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/config.rb"=>
      [Dor, :Config],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/version.rb"=>
      [Dor, :Version],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/services"=>
      [Dor, :Services],
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/datastreams"=>
      [Dor, :Datastreams]},
   @eager_load_exclusions=#<Set: {}>,
   @eager_loaded=false,
   @ignored=#<Set: {}>,
   @ignored_paths=#<Set: {}>,
   @inflector=#<DorServicesClientInflector:0x00007fdd1d8877a8>,
   @initialized_at=2019-05-23 15:53:37 -0500,
   @lazy_subdirs=
    {"Tasks"=>["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/tasks"],
     "Dor::Indexers"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/indexers"],
     "Dor::Utils"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/utils"],
     "Dor::Models"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/models"],
     "Dor::Workflow"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/workflow"],
     "Dor::ReleaseTags"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/release_tags"],
     "Dor::Services"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/services"],
     "Dor::Datastreams"=>
      ["/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/datastreams"]},
   @logger=nil,
   @mutex=#<Thread::Mutex:0x00007fdd1d8877f8>,
   @mutex2=#<Thread::Mutex:0x00007fdd1d8877d0>,
   @preloads=[],
   @reloading_enabled=false,
   @root_dirs={"/Users/jcoyne85/workspace/sul-dlss/dor-services/lib"=>true},
   @setup=false,
   @shadowed_files=
    #<Set: {"/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/certificate_authenticated_rest_resource_factory.rb",
     "/Users/jcoyne85/workspace/sul-dlss/dor-services/lib/dor/rest_resource_factory.rb"}>,
   @tag="8029fe",
   @to_unload={}>
@fxn
Copy link
Owner

fxn commented May 23, 2019

Hey!

I don't fully understand the situation. Let me ask you some questions.

I understand from the description that dor-services-client uses Zeitwerk, and dor-services does not. I also understand that dor-services depends on dor-services-client. So, at some point dor-services performs a require of some file from dor-services-client that defines its loader. Is that all right?

If yes, I do not get why the configured loader above has a root directory .../sul-dlss/dor-services/lib. That directory does not seem right for dor-services-client. Which is the explanation for that?

Can you also share the source code that instantiates and configures the Zeitwerk loader, and where is it located?

@jcoyne
Copy link
Contributor Author

jcoyne commented May 24, 2019

I think the problem was that we made our lib a relative require by zeitwerk. Making it an absolute path seems to have fixed the issue: https://github.com/sul-dlss/dor-services-client/pull/65/files

@jcoyne jcoyne closed this as completed May 24, 2019
@fxn
Copy link
Owner

fxn commented May 24, 2019

Oh yes, that is something to be careful about in gems.

Glad you found it.

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