lib/spoom/sorbet.rb in spoom-1.1.15 vs lib/spoom/sorbet.rb in spoom-1.1.16
- old
+ new
@@ -9,14 +9,37 @@
require "open3"
module Spoom
module Sorbet
+ class Error < StandardError
+ extend T::Sig
+
+ class Killed < Error; end
+ class Segfault < Error; end
+
+ sig { returns(ExecResult) }
+ attr_reader :result
+
+ sig do
+ params(
+ message: String,
+ result: ExecResult,
+ ).void
+ end
+ def initialize(message, result)
+ super(message)
+
+ @result = result
+ end
+ end
+
CONFIG_PATH = "sorbet/config"
GEM_PATH = T.let(Gem::Specification.find_by_name("sorbet-static").full_gem_path, String)
BIN_PATH = T.let((Pathname.new(GEM_PATH) / "libexec" / "sorbet").to_s, String)
+ KILLED_CODE = 137
SEGFAULT_CODE = 139
class << self
extend T::Sig
@@ -32,11 +55,20 @@
if sorbet_bin
arg.prepend(sorbet_bin)
else
arg.prepend("bundle", "exec", "srb")
end
- Spoom.exec(*T.unsafe(arg), path: path, capture_err: capture_err)
+ result = Spoom.exec(*T.unsafe(arg), path: path, capture_err: capture_err)
+
+ case result.exit_code
+ when KILLED_CODE
+ raise Error::Killed.new("Sorbet was killed.", result)
+ when SEGFAULT_CODE
+ raise Error::Segfault.new("Sorbet segfaulted.", result)
+ end
+
+ result
end
sig do
params(
arg: String,
@@ -67,17 +99,20 @@
capture_err: T::Boolean,
sorbet_bin: T.nilable(String),
).returns(T.nilable(String))
end
def srb_version(*arg, path: ".", capture_err: false, sorbet_bin: nil)
- result = T.let(T.unsafe(self).srb_tc(
- "--no-config",
- "--version",
- *arg,
- path: path,
- capture_err: capture_err,
- sorbet_bin: sorbet_bin,
- ), ExecResult)
+ result = T.let(
+ T.unsafe(self).srb_tc(
+ "--no-config",
+ "--version",
+ *arg,
+ path: path,
+ capture_err: capture_err,
+ sorbet_bin: sorbet_bin,
+ ),
+ ExecResult,
+ )
return nil unless result.status
result.out.split(" ")[2]
end