From 843c729b166f4ed26080b27a0f2829b55672310d Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Thu, 12 Sep 2024 10:39:55 -0700 Subject: [PATCH 1/2] Configuration errors should raise a specific exception Raising FPM::InvalidPackageConfiguration will allow the fpm command-line to print an error message and exit non-zero. Raising other exceptions will often produce a crash-like behavior which prints the exception and a stack trace. Stack traces are not helpful content in situations where a user has made a configuration error. --- lib/fpm/package/deb.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index 9f2a135fb..ba8975e79 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -73,7 +73,7 @@ class FPM::Package::Deb < FPM::Package option "--compression", "COMPRESSION", "The compression type to use, must " \ "be one of #{COMPRESSION_TYPES.join(", ")}.", :default => "gz" do |value| if !COMPRESSION_TYPES.include?(value) - raise ArgumentError, "deb compression value of '#{value}' is invalid. " \ + raise FPM::InvalidPackageConfiguration, "deb compression value of '#{value}' is invalid. " \ "Must be one of #{COMPRESSION_TYPES.join(", ")}" end value @@ -364,7 +364,7 @@ def extract_info(package) version_re = /^(?:([0-9]+):)?(.+?)(?:-(.*))?$/ m = version_re.match(parse.call("Version")) if !m - raise "Unsupported version string '#{parse.call("Version")}'" + raise FPM::InvalidPackageConfiguration, "Unsupported version string '#{parse.call("Version")}'" end self.epoch, self.version, self.iteration = m.captures @@ -504,15 +504,15 @@ def output(output_path) end if attributes[:source_date_epoch] == "0" logger.error("Alas, ruby's Zlib::GzipWriter does not support setting an mtime of zero. Aborting.") - raise "#{name}: source_date_epoch of 0 not supported." + raise FPM::InvalidPackageConfiguration, "#{name}: source_date_epoch of 0 not supported." end if not attributes[:source_date_epoch].nil? and not ar_cmd_deterministic? logger.error("Alas, could not find an ar that can handle -D option. Try installing recent gnu binutils. Aborting.") - raise "#{name}: ar is insufficient to support source_date_epoch." + raise FPM::InvalidPackageConfiguration, "#{name}: ar is insufficient to support source_date_epoch." end if not attributes[:source_date_epoch].nil? and not tar_cmd_supports_sort_names_and_set_mtime? logger.error("Alas, could not find a tar that can set mtime and sort. Try installing recent gnu tar. Aborting.") - raise "#{name}: tar is insufficient to support source_date_epoch." + raise FPM::InvalidPackageConfiguration, "#{name}: tar is insufficient to support source_date_epoch." end attributes[:deb_systemd] = [] @@ -525,7 +525,7 @@ def output(output_path) elsif [".service", ".timer"].include?(extname) name else - raise ArgumentError, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." + raise FPM::InvalidPackageConfiguration, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension." end dest_systemd = staging_path("lib/systemd/system/#{name_with_extension}") From e94f56c01ec7eedaa767345c05bc0560a4c38864 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Thu, 12 Sep 2024 10:48:55 -0700 Subject: [PATCH 2/2] Flag errors should use FPM::Package::InvalidArgument --- lib/fpm/package/deb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fpm/package/deb.rb b/lib/fpm/package/deb.rb index ba8975e79..0d536528f 100644 --- a/lib/fpm/package/deb.rb +++ b/lib/fpm/package/deb.rb @@ -73,7 +73,7 @@ class FPM::Package::Deb < FPM::Package option "--compression", "COMPRESSION", "The compression type to use, must " \ "be one of #{COMPRESSION_TYPES.join(", ")}.", :default => "gz" do |value| if !COMPRESSION_TYPES.include?(value) - raise FPM::InvalidPackageConfiguration, "deb compression value of '#{value}' is invalid. " \ + raise FPM::Package::InvalidArgument, "deb compression value of '#{value}' is invalid. " \ "Must be one of #{COMPRESSION_TYPES.join(", ")}" end value