Skip to content

Commit d72fdc7

Browse files
committed
Show the package name for which the error associated
1 parent e74e050 commit d72fdc7

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

src/cli.cr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,18 @@ end
176176
begin
177177
Shards.run
178178
rescue ex : OptionParser::InvalidOption
179-
Shards::Log.fatal { ex.message }
179+
Shards::Log.fatal(exception: ex) { ex.message }
180180
exit 1
181181
rescue ex : Shards::ParseError
182182
ex.to_s(STDERR)
183183
exit 1
184+
rescue ex : Shards::PackageError
185+
package = ex.package
186+
Shards::Log.error(exception: ex) { "Failed to install `#{package.name}`: #{ex.message}" }
187+
Shards::Log.debug { ex.inspect_with_backtrace }
188+
exit 1
184189
rescue ex : Shards::Error
185-
Shards::Log.error { ex.message }
190+
Shards::Log.error(exception: ex) { ex.message }
191+
Shards::Log.debug { ex.inspect_with_backtrace }
186192
exit 1
187193
end

src/commands/install.cr

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,19 @@ module Shards
6565
# packages are returned by the solver in reverse topological order,
6666
# so transitive dependencies are installed first
6767
packages.each do |package|
68-
# first install the dependency:
69-
next unless install(package)
70-
71-
# then execute the postinstall script
72-
# (with access to all transitive dependencies):
73-
package.postinstall
74-
75-
# always install executables because the path resolver never actually
76-
# installs dependencies:
77-
package.install_executables
68+
Log.with_context do
69+
Log.context.set package: package.name
70+
# first install the dependency:
71+
next unless install(package)
72+
73+
# then execute the postinstall script
74+
# (with access to all transitive dependencies):
75+
package.postinstall
76+
77+
# always install executables because the path resolver never actually
78+
# installs dependencies:
79+
package.install_executables
80+
end
7881
end
7982
end
8083

src/errors.cr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ module Shards
22
class Error < ::Exception
33
end
44

5+
class PackageError < Error
6+
getter package
7+
8+
def initialize(message, @package : Package)
9+
super message
10+
end
11+
end
12+
513
class Conflict < Error
614
getter package
715

src/package.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module Shards
114114
spec.executables.each do |name|
115115
exe_name = find_executable_file(Path[install_path], name)
116116
unless exe_name
117-
raise Shards::Error.new("Could not find executable #{name.inspect}")
117+
raise Shards::PackageError.new("Could not find executable #{name.inspect}", package: self)
118118
end
119119
Log.debug { "Install #{exe_name}" }
120120
source = File.join(install_path, exe_name)

0 commit comments

Comments
 (0)