Skip to content

Commit e596538

Browse files
committed
fix: improve error handling in bin/dev scripts per CodeRabbit feedback
- Replace ineffective rescue Errno::ENOENT with File.exist? pre-checks - Change exit! to exit 1 for better at_exit handler support The rescue blocks were dead code since system() calls to foreman/overmind don't raise Errno::ENOENT for missing files - they just return false.
1 parent 38bc6a2 commit e596538

File tree

2 files changed

+50
-38
lines changed
  • lib/generators/react_on_rails/bin
  • spec/dummy/bin

2 files changed

+50
-38
lines changed

lib/generators/react_on_rails/bin/dev

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,41 @@ def run_static_development
6767
# Generate React on Rails packs first
6868
generate_packs
6969

70-
if installed? "overmind"
71-
system "overmind start -f Procfile.dev-static-assets"
72-
elsif installed? "foreman"
73-
system "foreman start -f Procfile.dev-static-assets"
70+
procfile = "Procfile.dev-static-assets"
71+
unless File.exist?(procfile)
72+
warn <<~MSG
73+
ERROR:
74+
Please ensure `#{procfile}` exists in your project!
75+
MSG
76+
exit 1
77+
end
78+
79+
if installed?("overmind")
80+
system "overmind start -f #{procfile}"
81+
elsif installed?("foreman")
82+
system "foreman start -f #{procfile}"
7483
else
7584
warn <<~MSG
7685
NOTICE:
7786
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
7887
MSG
79-
exit!
88+
exit 1
8089
end
81-
rescue Errno::ENOENT
82-
warn <<~MSG
83-
ERROR:
84-
Please ensure `Procfile.dev-static-assets` exists in your project!
85-
MSG
86-
exit!
8790
end
8891

8992
def run_development(process)
9093
generate_packs
9194

92-
system "#{process} start -f Procfile.dev"
93-
rescue Errno::ENOENT
94-
warn <<~MSG
95-
ERROR:
96-
Please ensure `Procfile.dev` exists in your project!
97-
MSG
98-
exit!
95+
procfile = "Procfile.dev"
96+
unless File.exist?(procfile)
97+
warn <<~MSG
98+
ERROR:
99+
Please ensure `#{procfile}` exists in your project!
100+
MSG
101+
exit 1
102+
end
103+
104+
system "#{process} start -f #{procfile}"
99105
end
100106

101107
# Check for arguments
@@ -149,7 +155,7 @@ elsif ARGV[0] == "hmr" || ARGV[0].nil?
149155
NOTICE:
150156
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
151157
MSG
152-
exit!
158+
exit 1
153159
end
154160
else
155161
# Unknown argument

spec/dummy/bin/dev

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,41 @@ def run_static_development
6767
# Generate React on Rails packs first
6868
generate_packs
6969

70-
if installed? "overmind"
71-
system "overmind start -f Procfile.dev-static-assets"
72-
elsif installed? "foreman"
73-
system "foreman start -f Procfile.dev-static-assets"
70+
procfile = "Procfile.dev-static-assets"
71+
unless File.exist?(procfile)
72+
warn <<~MSG
73+
ERROR:
74+
Please ensure `#{procfile}` exists in your project!
75+
MSG
76+
exit 1
77+
end
78+
79+
if installed?("overmind")
80+
system "overmind start -f #{procfile}"
81+
elsif installed?("foreman")
82+
system "foreman start -f #{procfile}"
7483
else
7584
warn <<~MSG
7685
NOTICE:
7786
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
7887
MSG
79-
exit!
88+
exit 1
8089
end
81-
rescue Errno::ENOENT
82-
warn <<~MSG
83-
ERROR:
84-
Please ensure `Procfile.dev-static-assets` exists in your project!
85-
MSG
86-
exit!
8790
end
8891

8992
def run_development(process)
9093
generate_packs
9194

92-
system "#{process} start -f Procfile.dev"
93-
rescue Errno::ENOENT
94-
warn <<~MSG
95-
ERROR:
96-
Please ensure `Procfile.dev` exists in your project!
97-
MSG
98-
exit!
95+
procfile = "Procfile.dev"
96+
unless File.exist?(procfile)
97+
warn <<~MSG
98+
ERROR:
99+
Please ensure `#{procfile}` exists in your project!
100+
MSG
101+
exit 1
102+
end
103+
104+
system "#{process} start -f #{procfile}"
99105
end
100106

101107
# Check for arguments
@@ -149,7 +155,7 @@ elsif ARGV[0] == "hmr" || ARGV[0].nil?
149155
NOTICE:
150156
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
151157
MSG
152-
exit!
158+
exit 1
153159
end
154160
else
155161
# Unknown argument

0 commit comments

Comments
 (0)