1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
# frozen_string_literal: true
module RbSys
# Error is the base class for all errors raised by rb_sys.
class Error < StandardError; end
# Raised when a package is not found from the Cargo metadata.
class PackageNotFoundError < Error
def initialize(name)
msg = <<~MSG.chomp.tr("\n", " ")
Could not find Cargo package metadata for #{@name.inspect}. Please
check that #{@name.inspect} matches the crate name in your
Cargo.toml."
MSG
super(msg)
end
end
# Raised when Cargo metadata cannot be parsed.
class CargoMetadataError < Error
def initialize(err, stderr)
msg = <<~MSG.chomp.tr("\n", " ")
Could not infer Rust crate information using `cargo metadata`.
Original error was:
#{err.class}: #{err.message}
Things to check:
- Check that your ext/*/Cargo.toml at is valid
- If you are using a workspace, make sure you are the root Cargo.toml exists
- Make sure `cargo` is installed and in your PATH
MSG
if !stderr.empty?
indented_stderr = stderr.lines.map { |line| " #{line}" }.join
msg << "Stderr from `cargo metadata` was:\n#{indented_stderr}"
end
super(msg)
end
end
end
|