Skip to content

Only add adapter errors that are defined - #745

Open
p8 wants to merge 1 commit into
rpush:masterfrom
p8:fix-sqlite-loading
Open

p8 wants to merge 1 commit into
rpush:masterfrom
p8:fix-sqlite-loading

Conversation

@p8

@p8 p8 commented May 29, 2026 •

Copy link
Copy Markdown

Instead of defining errors that aren't defined, only add the errors if they are defined.

If SQLite3 isn't defined, it should not be defined by Rpush. Other dependencies could break if they use logic to test for defined constants.

This also prevents issues where some of the error classes start inheriting from other classes than StandardError.

This fixes an issue with Zeitwerk 2.8 where it tries to load a file named sqlite3 (in an application that doesn't use sqlite3):

      [2026-05-29 14:08:00][ERROR] Failed to load 'active_record' storage backend.:20
      [2026-05-29 14:08:00][ERROR] LoadError, cannot load such file -- sqlite3
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
      /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'Kernel#require'
      /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'
      /vendor/bundle/ruby/3.4.0/gems/rpush-9.2.0/lib/rpush/daemon/store/active_record/reconnectable.rb:13:in '<top (required)>'
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
      /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in 'Kernel#require'
      /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'
      /vendor/bundle/ruby/3.4.0/gems/rpush-9.2.0/lib/rpush/daemon/store/active_record.rb:3:in '<top (required)>'
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
      /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
      /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in 'Kernel#require'
      /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'

Instead of defining errors that aren't defined, only add the errors if
they are defined.

If SQLite3 isn't defined, it should not be defined by Rpush.
Other dependencies could break if they use logic to test for defined constants.

This fixes an issue with Zeitwerk 2.8 where it tries to load a file named sqlite3:

          [2026-05-29 14:08:00][ERROR] Failed to load 'active_record' storage backend.:20
          [2026-05-29 14:08:00][ERROR] LoadError, cannot load such file -- sqlite3
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
          /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in 'Kernel#require'
          /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'
          /vendor/bundle/ruby/3.4.0/gems/rpush-9.2.0/lib/rpush/daemon/store/active_record/reconnectable.rb:13:in '<top (required)>'
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
          /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in 'Kernel#require'
          /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'
          /vendor/bundle/ruby/3.4.0/gems/rpush-9.2.0/lib/rpush/daemon/store/active_record.rb:3:in '<top (required)>'
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
          /usr/lib/ruby/versions/3.4.9/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
          /vendor/bundle/ruby/3.4.0/gems/bootsnap-1.24.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:33:in 'Kernel#require'
          /vendor/bundle/ruby/3.4.0/gems/zeitwerk-2.8.0/lib/zeitwerk/core_ext/kernel.rb:34:in 'Kernel#require'
@p8
p8 force-pushed the fix-sqlite-loading branch from 9754e66 to ba2e2c8 Compare May 29, 2026 17:02

@brethren brethren left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against the Ruby 3.4.10 / Rails 7.2 / Zeitwerk 2.8 failure in a PostgreSQL-only deployment. This avoids autoloading or defining unused adapter constants while preserving reconnect handling for adapters that are actually loaded.

@brethren

brethren commented Aug 21, 2026 •

Copy link
Copy Markdown

@benlangfeld Could you please review and merge this?

We reproduced the reported failure in a PostgreSQL-only deployment using Ruby 3.4.10, Rails/Active Record 7.2.3.2, and Zeitwerk 2.8.3:

Failed to load the active_record storage backend: LoadError, cannot load such file -- sqlite3, from rpush-9.2.0/lib/rpush/daemon/store/active_record/reconnectable.rb:13.

Applying this one-file change to the 9.2.0 image resolves startup without installing SQLite or defining unused adapter constants. I reviewed and approved the PR; our account does not have merge access to this repository. A tagged release containing it would let downstream applications remove their temporary vendored patch.

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

Successfully merging this pull request may close these issues.

2 participants