Error when locally launching rails app: "Permission denied @ dir_s_mkdir - /db"

33 Views Asked by At

I'm encountering an irritatingly persistent error in my Rails application. Here's the highlighted log that pops when I open the link for my app after running rails server:

Permission denied @ dir_s_mkdir - /db
Extracted source (around line #32):
        config[:database] = File.expand_path(config[:database], Rails.root) if defined?(Rails.root)
        dirname = File.dirname(config[:database])
        Dir.mkdir(dirname) unless File.directory?(dirname)
      end
      db = SQLite3::Database.new(

In addition, there's this below:

activerecord (7.0.4) lib/active_record/connection_adapters/sqlite3_adapter.rb:32:in `mkdir'
activerecord (7.0.4) lib/active_record/connection_adapters/sqlite3_adapter.rb:32:in `sqlite3_connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
activerecord (7.0.4) lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
activerecord (7.0.4) lib/active_record/connection_handling.rb:313:in `retrieve_connection'
activerecord (7.0.4) lib/active_record/connection_handling.rb:280:in `connection'
activerecord (7.0.4) lib/active_record/migration.rb:613:in `connection'
activerecord (7.0.4) lib/active_record/migration.rb:608:in `build_watcher'
activerecord (7.0.4) lib/active_record/migration.rb:590:in `block in call'
activerecord (7.0.4) lib/active_record/migration.rb:589:in `synchronize'
activerecord (7.0.4) lib/active_record/migration.rb:589:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (7.0.4) lib/active_support/callbacks.rb:99:in `run_callbacks'
actionpack (7.0.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'
railties (7.0.4) lib/rails/rack/logger.rb:40:in `call_app'
railties (7.0.4) lib/rails/rack/logger.rb:25:in `block in call'
activesupport (7.0.4) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (7.0.4) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (7.0.4) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (7.0.4) lib/rails/rack/logger.rb:25:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.4) lib/rack/method_override.rb:24:in `call'
rack (2.2.4) lib/rack/runtime.rb:22:in `call'
activesupport (7.0.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/server_timing.rb:61:in `block in call'
actionpack (7.0.4) lib/action_dispatch/middleware/server_timing.rb:26:in `collect_events'
actionpack (7.0.4) lib/action_dispatch/middleware/server_timing.rb:60:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/static.rb:23:in `call'
rack (2.2.4) lib/rack/sendfile.rb:110:in `call'
actionpack (7.0.4) lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
railties (7.0.4) lib/rails/engine.rb:530:in `call'
puma (5.6.5) lib/puma/configuration.rb:252:in `call'
puma (5.6.5) lib/puma/request.rb:77:in `block in handle_request'
puma (5.6.5) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
puma (5.6.5) lib/puma/request.rb:76:in `handle_request'
puma (5.6.5) lib/puma/server.rb:443:in `process_client'
puma (5.6.5) lib/puma/thread_pool.rb:147:in `block in spawn_thread'

For context, it's a very simple app as I'm only a newbie. It's just sending an email with the click of a button. The app worked perfectly locally for weeks, until two days ago that I began tinkering again to deploy it on Fly.io. It launched locally every single time, until it randomly didn't. All I can think I did differently was enable virtualisation and upgraded from wsl1 to wsl2.

None of the db commands work on my terminal for the project, naturally, but I'm able to create other files and folders outside of db. The issue is specifically with db, it appears, but deleting and recreating the file and database hasn't worked at all.

After running all possible chmod commands, ensuring I have all permissions, checking and double checking my environments, and the paths for my directories, I reverted the wsl2 changes, to no avail. I tested my untouched backups from weeks ago and they yielded the same error. So, I created a new rails app to test it out. It gave the same error. I downloaded other GitHub projects to test it out. Same error. I concluded it wasn't the code inside the projects, so I decided to create a new app in a different language (python), and it launched perfectly. I ruled out my system and thought the issue was with rails. Maybe wsl2 messed it up, I thought. So, I completely uninstalled ruby, rails, and all of their dependencies. Reinstalled from scratch. Aaaaaaaaand I get the same error.

I'm stumped. As a newbie, I'm almost ripping my hair out because I just don't understand what the source of the error is. I've been through so many Permission denied @ dir_s_mkdir error posts in this site and GitHub, but none of the solutions help. Besides asking for help, all I can think to do is restoring my system to how it was before enabling virtualisation and upgrading to wsl2 (I created a system restore just in case) to see if it helps, but I'd rather it be the absolute last resort.

0

There are 0 best solutions below