PixarAnimationStudios / ruby-jss

ruby-jss provides native ruby access to the REST APIs of Jamf Pro, an enterprise/education tool for managing Apple devices, from jamf.com. The Jamf module provides access to both APIs. Jamf Pro objects are implemented as classes and interact with each other. Authentication tokens, data format and other details are handled under the hood to allow simpler, intuitive automation of Jamf-related tasks.
http://pixaranimationstudios.github.io/jss-api-gem/index.html
Other
99 stars 30 forks source link

Production mode error: uninitialized constant Jamf::OAPISchemas::MobileDeviceResponse (NameError) #101

Closed jcruce13 closed 2 weeks ago

jcruce13 commented 3 weeks ago

When running in Production mode I got the following error.

web-1 | Exiting web-1 | /usr/local/bundle/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:79:in <class:MobileDeviceInventorySearchResults>': uninitialized constant Jamf::OAPISchemas::MobileDeviceResponse (NameError) web-1 | web-1 | class: Jamf::OAPISchemas::MobileDeviceResponse, web-1 | ^^^^^^^^^^^^^^^^^^^^^^ web-1 | Did you mean? Jamf::OAPISchemas::MobileDevicePrestage web-1 | Jamf::MobileDevicePrestage web-1 | from /usr/local/bundle/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:64:in' web-1 | from /usr/local/bundle/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:30:in <module:Jamf>' web-1 | from /usr/local/bundle/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:25:in

' web-1 | from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in require' web-1 | from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:inrequire' web-1 | from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in require' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/kernel.rb:26:inrequire' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/cref.rb:91:in const_get' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/cref.rb:91:inget' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:173:in block in actual_eager_load_dir' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/helpers.rb:47:inblock in ls' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/helpers.rb:25:in each' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/helpers.rb:25:inls' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:168:in actual_eager_load_dir' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:17:inblock (2 levels) in eager_load' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:16:in each' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:16:inblock in eager_load' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:10:in synchronize' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader/eager_load.rb:10:ineager_load' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader.rb:413:in block in eager_load_all' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader.rb:411:ineach' web-1 | from /usr/local/bundle/gems/zeitwerk-2.6.16/lib/zeitwerk/loader.rb:411:in eager_load_all' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/application/finisher.rb:74:inblock in ' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/initializable.rb:32:in instance_exec' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/initializable.rb:32:inrun' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/initializable.rb:61:in block in run_initializers' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:228:inblock in tsort_each' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:431:ineach_strongly_connected_component_from' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:349:in block in each_strongly_connected_component' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:347:ineach' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in call' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:347:ineach_strongly_connected_component' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:226:in tsort_each' web-1 | from /usr/local/lib/ruby/3.2.0/tsort.rb:205:intsort_each' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/initializable.rb:60:in run_initializers' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/application.rb:372:ininitialize!' web-1 | from /usr/src/app/config/environment.rb:5:in <main>' web-1 | from config.ru:3:inrequire_relative' web-1 | from config.ru:3:in block in <main>' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/builder.rb:116:ineval' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/builder.rb:116:in new_from_string' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/builder.rb:105:inload_file' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/builder.rb:66:in parse_file' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:349:inbuild_app_and_options_from_config' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:249:in app' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:422:inwrapped_app' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:312:in block in start' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:379:inhandle_profiling' web-1 | from /usr/local/bundle/gems/rack-2.2.9/lib/rack/server.rb:311:in start' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/commands/server/server_command.rb:38:instart' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/commands/server/server_command.rb:143:in block in perform' web-1 | from <internal:kernel>:90:intap' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/commands/server/server_command.rb:134:in perform' web-1 | from /usr/local/bundle/gems/thor-1.3.1/lib/thor/command.rb:28:inrun' web-1 | from /usr/local/bundle/gems/thor-1.3.1/lib/thor/invocation.rb:127:in invoke_command' web-1 | from /usr/local/bundle/gems/thor-1.3.1/lib/thor.rb:527:indispatch' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/command/base.rb:87:in perform' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/command.rb:48:ininvoke' web-1 | from /usr/local/bundle/gems/railties-7.0.8.4/lib/rails/commands.rb:18:in <main>' web-1 | from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:inrequire' web-1 | from <internal:/usr/local/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in require' web-1 | from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:inrequire' web-1 | from /usr/src/app/bin/rails:4:in `
' web-1 exited with code 1

rod-eligible commented 3 weeks ago

Having the same issue, can a new tag be created from latest master branch merges?

glenfarclas17 commented 3 weeks ago

This looks like the same issue described in #98 and fixed in #100 - I just pushed those changes as v 4.1.1b1

Could you give that a try gem install ruby-jss --pre should install it.

Also - are you making Zeitwerk "eager-load" every class by touching '/tmp/ruby-jss-zeitwerk-eager-load' ? If not, I'm not sure why it would be trying to load that file!

Thanks for the reports!

rod-eligible commented 3 weeks ago

@glenfarclas17 it works on my desktop, but can you please please please 🙏 create a tag for it on https://github.com/PixarAnimationStudios/ruby-jss/tags ? for the server we use jfrog and its kind of restrictive, I cannot install it like we do in my desktop, it asks for a tag 🙏

glenfarclas17 commented 3 weeks ago

Nope - Hold off - I just ran it with eager load and now its complaining about another class - I'll let you know when I get this figured out.

glenfarclas17 commented 3 weeks ago

I will tag after some more testing here when its released!

rod-eligible commented 3 weeks ago

Just to add a bit more of info, this is the current error I have on a server, I believe it is related:

/u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:79:in `<class:MobileDeviceInventorySearchResults>': uninitialized constant Jamf::OAPISchemas::MobileDeviceResponse (NameError)

          class: Jamf::OAPISchemas::MobileDeviceResponse,
                                  ^^^^^^^^^^^^^^^^^^^^^^
Did you mean?  Jamf::OAPISchemas::MobileDevicePrestage
               Jamf::MobileDevicePrestage
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:64:in `<module:OAPISchemas>'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:30:in `<module:Jamf>'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/ruby-jss-4.1.0/lib/jamf/api/jamf_pro/oapi_schemas/mobile_device_inventory_search_results.rb:25:in `<top (required)>'
        from <internal:/opt/ruby32/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/opt/ruby32/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/kernel.rb:30:in `require'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/helpers.rb:135:in `const_get'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/helpers.rb:135:in `cget'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:169:in `block in actual_eager_load_dir'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/helpers.rb:40:in `block in ls'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/helpers.rb:25:in `each'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/helpers.rb:25:in `ls'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:164:in `actual_eager_load_dir'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:17:in `block (2 levels) in eager_load'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:16:in `each'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:16:in `block in eager_load'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:10:in `synchronize'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader/eager_load.rb:10:in `eager_load'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader.rb:329:in `block in eager_load_all'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader.rb:327:in `each'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/zeitwerk-2.6.8/lib/zeitwerk/loader.rb:327:in `eager_load_all'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/application/finisher.rb:74:in `block in <module:Finisher>'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/initializable.rb:32:in `instance_exec'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/initializable.rb:32:in `run'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:347:in `each'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:347:in `call'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
        from /opt/ruby32/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/initializable.rb:60:in `run_initializers'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/railties-7.0.5.1/lib/rails/application.rb:372:in `initialize!'
        from /u/apps/policies-staging/releases/20240624094538/config/environment.rb:5:in `<top (required)>'
        from <internal:/opt/ruby32/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/opt/ruby32/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from config.ru:5:in `block in <main>'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/rack-2.2.6.4/lib/rack/builder.rb:125:in `instance_eval'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/rack-2.2.6.4/lib/rack/builder.rb:125:in `initialize'
        from config.ru:1:in `new'
        from config.ru:1:in `<main>'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn.rb:54:in `eval'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn.rb:54:in `block in builder'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:821:in `build_app!'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:140:in `start'
        from /u/apps/policies-staging/shared/bundle/ruby/3.2.0/gems/unicorn-6.1.0/bin/unicorn:128:in `<top (required)>'
        from /u/apps/policies-staging/current/bin_bundle/unicorn:27:in `load'
        from /u/apps/policies-staging/current/bin_bundle/unicorn:27:in `<main>'
glenfarclas17 commented 3 weeks ago

Yeah, That's the same issue

I'm still not sure why its eager-loading - it should only do that if youve touched a temp file, and its really only for testing, shouldn't be done on a server (and I need to remember to do it when I test!)

glenfarclas17 commented 3 weeks ago

Ok I just pushed v4.1.1b3, which you should be able to get with the same gem install ruby-jss --pre .... fixes another wierd problem with autoloading and class naming - and reinforces my thoughts on not using the OAPI3 schema quite so automatically.

To test please first do touch /tmp/ruby-jss-zeitwerk-eager-load and that will make require ruby-jss load in all the files at once. You shouldn't see any errors when you do that.

I'll run some tests here on various servers and if it looks good I'll do a release with a tag

Sorry for the inconvenience! -Chris

glenfarclas17 commented 2 weeks ago

Version 4.1.1 has been tagged and released - hopefully with enough testing! Please let me know if you still see problems!

Cheers, -Chris