From fdd3fca6a6d38bc90bf870434fae043e49c21b14 Mon Sep 17 00:00:00 2001 From: Vasyl Kuzmyk Date: Sat, 23 Nov 2024 16:14:55 +0000 Subject: [PATCH 1/2] Add more descriptive error to file loading --- lib/que/command_line_interface.rb | 1 + spec/que/command_line_interface_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/que/command_line_interface.rb b/lib/que/command_line_interface.rb index 7e9f2e67..05737a47 100644 --- a/lib/que/command_line_interface.rb +++ b/lib/que/command_line_interface.rb @@ -200,6 +200,7 @@ def parse( require file rescue LoadError => e output.puts "Could not load file '#{file}': #{e}" + output.puts "Your file path should look like you're running a script, e.g. `./path/to/file.rb`" unless file.start_with?('./') return 1 end end diff --git a/spec/que/command_line_interface_spec.rb b/spec/que/command_line_interface_spec.rb index 7ee69c31..d005c0f2 100644 --- a/spec/que/command_line_interface_spec.rb +++ b/spec/que/command_line_interface_spec.rb @@ -171,6 +171,22 @@ def write_file LOADED_FILES ) end + + it "should raise an error if file is not leading with ./" do + name = write_file + code = execute "#{name}" + assert_equal 1, code + + assert_equal [ + "Could not load file '#{name}': cannot load such file -- #{name}", + "Your file path should look like you're running a script, e.g. `./path/to/file.rb`" + ], output.messages + + assert_equal( + {}, + LOADED_FILES + ) + end end describe "should start up a locker" do From 3a454e81e7f4c29f0387d53b5c71b212476942a5 Mon Sep 17 00:00:00 2001 From: Vasyl Kuzmyk Date: Tue, 26 Nov 2024 14:21:51 +0000 Subject: [PATCH 2/2] Drop custom error --- lib/que/command_line_interface.rb | 8 +------- spec/que/command_line_interface_spec.rb | 23 ++--------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/lib/que/command_line_interface.rb b/lib/que/command_line_interface.rb index 05737a47..7d39d03d 100644 --- a/lib/que/command_line_interface.rb +++ b/lib/que/command_line_interface.rb @@ -196,13 +196,7 @@ def parse( end args.each do |file| - begin - require file - rescue LoadError => e - output.puts "Could not load file '#{file}': #{e}" - output.puts "Your file path should look like you're running a script, e.g. `./path/to/file.rb`" unless file.start_with?('./') - return 1 - end + require File.expand_path(file) end Que.logger ||= Logger.new(STDOUT) diff --git a/spec/que/command_line_interface_spec.rb b/spec/que/command_line_interface_spec.rb index d005c0f2..63af2c88 100644 --- a/spec/que/command_line_interface_spec.rb +++ b/spec/que/command_line_interface_spec.rb @@ -121,7 +121,7 @@ def write_file it "should infer the default require file if it exists" do filename = write_file - assert_successful_invocation "", default_require_file: "./#{filename}.rb" + assert_successful_invocation "", default_require_file: "#{filename}.rb" assert_equal( {filename => true}, @@ -161,32 +161,13 @@ def write_file it "should raise an error if any of the files don't exist" do name = write_file - code = execute "./#{name} ./nonexistent_file" - assert_equal 1, code - - assert_equal ["Could not load file './nonexistent_file': cannot load such file -- ./nonexistent_file"], output.messages + assert_raises(LoadError) { execute "#{name} ./nonexistent_file" } assert_equal( {name => true}, LOADED_FILES ) end - - it "should raise an error if file is not leading with ./" do - name = write_file - code = execute "#{name}" - assert_equal 1, code - - assert_equal [ - "Could not load file '#{name}': cannot load such file -- #{name}", - "Your file path should look like you're running a script, e.g. `./path/to/file.rb`" - ], output.messages - - assert_equal( - {}, - LOADED_FILES - ) - end end describe "should start up a locker" do