Rails template task (with LOCATION) raises Errno::ENOENT: No such file or directory @ rb_sysopen

It looks like it is not a Rails bug, but I am not sure for now. I can not use any template on railsbytes. But my project was created by using ~21 templates 7 months ago. So, it could be a bug in older Rails 6.

I love to use templates and created a lot of templates on my own. Some time ago, I found out that I can no longer use (my) templates on one of the projects, because I get the following error (with --trace):

rails app:template --trace LOCATION='https://railsbytes.com/script/x9Qsva'
** Invoke app:template (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute app:template
rails aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - https://railsbytes.com/script/x9Qsva
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/actions.rb:222:in `initialize'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/actions.rb:222:in `open'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/actions.rb:222:in `apply'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/tasks/framework.rake:15:in `block (2 levels) in <main>'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/command.rb:50:in `invoke'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/railties-6.1.4.1/lib/rails/commands.rb:18:in `<main>'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
~/Documents/projects/rails/project/bin/rails:5:in `<top (required)>'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/client/rails.rb:30:in `load'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/client/rails.rb:30:in `call'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/client/command.rb:7:in `call'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/client.rb:30:in `run'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/bin/spring:49:in `<top (required)>'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/binstub.rb:11:in `load'
~/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/spring-3.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
<internal:~/.rbenv/versions/3.0.3/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:~/.rbenv/versions/3.0.3/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
~/Documents/projects/rails/project/bin/spring:10:in `block in <top (required)>'
<internal:kernel>:90:in `tap'
~/Documents/projects/rails/project/bin/spring:7:in `<top (required)>'
bin/rails:2:in `load'
bin/rails:2:in `<main>'
Tasks: TOP => app:template

On a new Rails project, it will work as expected. But I do not have any idea how to find the reason?! It is not a public project. But I did some comparison with a new app, created fresh with rails new command. I did not find any difference.

My project environment (same error on Docker):

Rails 6.1.4.1
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [arm64-darwin21]
ProductName:	macOS
ProductVersion:	12.0.1
BuildVersion:	21A559

This app was created 7 months ago, using this template, which includes a lot of private templates too. But I use (with my students) and update this template for more than ~3 years. Also, I created a lot of different projects since then, all of them working as expected with (my) templates. The reason for this error is in this one project.

The new app, used for comparison (I did not find any difference):

rails _6.1.4_ new sample_app --database=postgresql -m https://railsbytes.com/script/VWesY4
...
Rails 6.1.4.1
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [arm64-darwin21]

Any idea or help?

Just found an app, created around the same time as not working project. And there it works -__-.

Cool, I found the reason! Git helped to find which commit introduced this error. And the winner is: license_finder gem. :smiley:

My Gemfile.lock in this project has these changes, when I add license_finder.

diff --git a/Gemfile.lock b/Gemfile.lock
index 0242e853..cf912c76 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -131,13 +131,6 @@ GEM
       letter_opener (~> 1.7)
       railties (>= 5.2)
       rexml
+    license_finder (6.14.2)
+      bundler
+      rubyzip (>= 1, < 3)
+      thor (~> 1.0.1)
+      tomlrb (>= 1.3, < 2.1)
+      with_env (= 1.1.0)
+      xml-simple (~> 1.1.5)
     listen (3.7.0)
       rb-fsevent (~> 0.10, >= 0.10.3)
       rb-inotify (~> 0.9, >= 0.9.10)
-    regexp_parser (2.2.0)
+    regexp_parser (2.1.1)
     reverse_markdown (2.1.1)
       nokogiri
     rexml (3.2.5)
@@ -228,7 +221,7 @@ GEM
       rubocop-ast (>= 0.6.0)
       ruby-progressbar (~> 1.7)
       unicode-display_width (>= 1.4.0, < 2.0)
-    rubocop-ast (1.14.0)
+    rubocop-ast (1.13.0)
       parser (>= 3.0.1.1)
     rubocop-packaging (0.5.1)
       rubocop (>= 0.89, < 2.0)
@@ -309,9 +302,8 @@ GEM
       activesupport (>= 5.2)
       sprockets (>= 3.0.0)
     temple (0.8.2)
-    thor (1.1.0)
+    thor (1.0.1)
     tilt (2.0.10)
+    tomlrb (2.0.1)
     turbolinks (5.2.1)
       turbolinks-source (~> 5.2)
     turbolinks-source (5.2.0)
@@ -337,9 +329,6 @@ GEM
     websocket-driver (0.7.5)
       websocket-extensions (>= 0.1.0)
     websocket-extensions (0.1.5)
+    with_env (1.1.0)
+    xml-simple (1.1.9)
+      rexml
     xpath (3.2.0)
       nokogiri (~> 1.8)
     yard (0.9.27)
@@ -363,7 +352,6 @@ DEPENDENCIES
   html2slim (~> 0.2.0)
   jbuilder (~> 2.7)
   letter_opener_web
+  license_finder
   listen (~> 3.3)
   pg (~> 1.1)

So, after adding license_finder to my project, I will get this Errno::ENOENT: No such file or directory @ rb_sysopen error.

In addition, I was unable to perform a bundle install with the existing Gemfile.lock on this commit. So I recreated it. However, this error seems to have occurred beforehand in commits.

Because I use this gem on every project too, I checked the changes, added by this gem, in corresponding commit of the new project (reference project I created yesterday).

diff --git a/Gemfile.lock b/Gemfile.lock
index c5ec8b5..42f2ce5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -109,6 +109,13 @@ GEM
       rexml
     kramdown-parser-gfm (1.1.0)
       kramdown (~> 2.0)
+    license_finder (6.0.0)
+      bundler
+      rubyzip (>= 1, < 3)
+      thor
+      toml (= 0.2.0)
+      with_env (= 1.1.0)
+      xml-simple
     listen (3.7.0)
       rb-fsevent (~> 0.10, >= 0.10.3)
       rb-inotify (~> 0.9, >= 0.9.10)
@@ -134,6 +141,7 @@ GEM
     parallel (1.21.0)
     parser (3.0.3.1)
       ast (~> 2.4.1)
+    parslet (1.8.2)
     pg (1.2.3)
     public_suffix (4.0.6)
     puma (5.5.2)
@@ -283,6 +291,8 @@ GEM
     temple (0.8.2)
     thor (1.1.0)
     tilt (2.0.10)
+    toml (0.2.0)
+      parslet (~> 1.8.0)
     turbolinks (5.2.1)
       turbolinks-source (~> 5.2)
     turbolinks-source (5.2.0)
@@ -308,6 +318,9 @@ GEM
     websocket-driver (0.7.5)
       websocket-extensions (>= 0.1.0)
     websocket-extensions (0.1.5)
+    with_env (1.1.0)
+    xml-simple (1.1.9)
+      rexml
     xpath (3.2.0)
       nokogiri (~> 1.8)
     yard (0.9.27)
@@ -327,6 +340,7 @@ DEPENDENCIES
   database_cleaner (~> 1.8, >= 1.8.5)
   html2slim (~> 0.2.0)
   jbuilder (~> 2.7)
+  license_finder
   listen (~> 3.3)
   meta_request (~> 0.7.3)
   pg (~> 1.1)

I get an older version of license_finder on a new project, with different dependencies :woozy_face:.

I created an issue for this Rails template task (with LOCATION) raises Errno::ENOENT: No such file or directory @ rb_sysopen · Issue #866 · pivotal/LicenseFinder · GitHub.

OK, after figuring out, what is the cause, the fix was easy.

  • Remove license_finder from Gemfile
  • Run bundle install
  • Add license_finder to Gemfile again
  • Run bundle install

Now my changes in Gemfile.lock looking the same as in a new, fresh Rails project. It will add license_finder (6.0.0) and not license_finder (6.14.2). The error disappears.