From c1a0fa2beb57f73b0494ebd9b69341f5e48b0390 Mon Sep 17 00:00:00 2001 From: TimoKats Date: Fri, 27 Dec 2024 09:47:56 +0100 Subject: [PATCH 1/2] fix error handling --- main.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main.rb b/main.rb index c9db91e..8a375bc 100644 --- a/main.rb +++ b/main.rb @@ -16,10 +16,18 @@ def initialize(filename, version_regex) end def read_versions() - File.open(@filename, "r") do |f| - f.each_line do |line| - @code_tags += line.scan(@version_regex) + begin + File.open(@filename, "r") do |f| + f.each_line do |line| + @code_tags += line.scan(@version_regex) + end end + rescue Errno::ENOENT => e + $stderr.puts "Error: #{e}" + exit -1 + rescue TypeError => e + $stderr.puts "Error: #{e} (Probably invalid VERSION_REGEX)" + exit -1 end end @@ -39,13 +47,17 @@ def version_updated() end begin - regex = ENV["VERSION_REGEX"] || "/[v]\\d.\\d.\\d/" + regex = ENV["VERSION_REGEX"] filename = ENV["FILENAME"] || "" if filename.empty? raise "No filename passed as env." end + if regex.empty? + regex = "/[v]\\d.\\d.\\d/" + end + project = Project.new(filename, eval(regex)) if not project.version_updated raise "Version in code not updated." From 8458acc314cb55c04190e9b5d6f545c5d5ce2b2e Mon Sep 17 00:00:00 2001 From: TimoKats Date: Fri, 27 Dec 2024 09:50:43 +0100 Subject: [PATCH 2/2] add env empty string --- main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.rb b/main.rb index 8a375bc..70b37a8 100644 --- a/main.rb +++ b/main.rb @@ -47,7 +47,7 @@ def version_updated() end begin - regex = ENV["VERSION_REGEX"] + regex = ENV["VERSION_REGEX"] || "" filename = ENV["FILENAME"] || "" if filename.empty?