File tree Expand file tree Collapse file tree 5 files changed +27
-14
lines changed Expand file tree Collapse file tree 5 files changed +27
-14
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ pub fn get_manifests<P: AsRef<Path>>(path: P) -> Result<Vec<Manifest>> {
42
42
}
43
43
44
44
fn parse_cargo_manifest ( path : & Path ) -> Result < Manifest > {
45
- let m = cargo_toml:: Manifest :: from_path ( path) ?;
45
+ let m = cargo_toml:: Manifest :: from_path ( path)
46
+ . with_context ( || format ! ( "Failed to parse Cargo.toml at '{}'" , path. display( ) ) ) ?;
46
47
let package = m. package . context ( "Not a package (only a workspace)" ) ?;
47
48
let description = package. description ( ) . map ( |v| v. into ( ) ) ;
48
49
@@ -57,7 +58,8 @@ fn parse_cargo_manifest(path: &Path) -> Result<Manifest> {
57
58
}
58
59
59
60
fn parse_npm_manifest ( path : & Path ) -> Result < Manifest > {
60
- let package = npm_package_json:: Package :: from_path ( path) ?;
61
+ let package = npm_package_json:: Package :: from_path ( path)
62
+ . with_context ( || format ! ( "Failed to parse package.json at '{}'" , path. display( ) ) ) ?;
61
63
Ok ( Manifest {
62
64
manifest_type : ManifestType :: Npm ,
63
65
number_of_dependencies : package. dependencies . len ( ) ,
Original file line number Diff line number Diff line change @@ -21,8 +21,14 @@ pub fn get_loc_by_language_sorted(
21
21
) -> Result < Vec < ( Language , usize ) > > {
22
22
let locs = get_locs ( dir, globs_to_exclude, language_types, include_hidden) ;
23
23
24
- let loc_by_language =
25
- get_loc_by_language ( & locs) . context ( "Could not find any source code in this repository" ) ?;
24
+ let loc_by_language = get_loc_by_language ( & locs) . with_context ( || {
25
+ format ! (
26
+ "No source code found in the repository at '{}'. \
27
+ Note: Some language types (prose, data) are excluded by default. \
28
+ Consider using the '--type' option to include them.",
29
+ dir. display( )
30
+ )
31
+ } ) ?;
26
32
27
33
let loc_by_language_sorted = sort_by_loc ( loc_by_language) ;
28
34
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ impl Detector {
22
22
pub fn new ( ) -> Result < Self > {
23
23
match Store :: from_cache ( CACHE_DATA ) {
24
24
Ok ( store) => Ok ( Self { store } ) ,
25
- Err ( _ ) => {
26
- bail ! ( "Could not initialize the license detector" )
25
+ Err ( e ) => {
26
+ bail ! ( "Could not initialize the license detector: {}" , e )
27
27
}
28
28
}
29
29
}
Original file line number Diff line number Diff line change @@ -147,14 +147,16 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
147
147
& repo,
148
148
cli_options. info . hide_token ,
149
149
cli_options. info . http_url ,
150
- ) ?;
150
+ )
151
+ . context ( "Failed to determine repository URL" ) ?;
151
152
152
153
let git_metrics = traverse_commit_graph (
153
154
& repo,
154
155
cli_options. info . no_bots . clone ( ) ,
155
156
cli_options. info . churn_pool_size ,
156
157
cli_options. info . no_merges ,
157
- ) ?;
158
+ )
159
+ . context ( "Failed to traverse Git commit history" ) ?;
158
160
let true_color = match cli_options. ascii . true_color {
159
161
When :: Always => true ,
160
162
When :: Never => false ,
Original file line number Diff line number Diff line change @@ -31,10 +31,13 @@ pub struct Printer<W> {
31
31
32
32
impl < W : Write > Printer < W > {
33
33
pub fn new ( writer : W , info : Info , cli_options : CliOptions ) -> Result < Self > {
34
- let image = match cli_options. image . image {
35
- Some ( p) => Some ( image:: open ( p) . context ( "Could not load the specified image" ) ?) ,
36
- None => None ,
37
- } ;
34
+ let image =
35
+ match cli_options. image . image {
36
+ Some ( p) => Some ( image:: open ( & p) . with_context ( || {
37
+ format ! ( "Could not load the image file at '{}'" , p. display( ) )
38
+ } ) ?) ,
39
+ None => None ,
40
+ } ;
38
41
39
42
let image_backend = if image. is_some ( ) {
40
43
cli_options
@@ -83,7 +86,7 @@ impl<W: Write> Printer<W> {
83
86
let image_backend = self
84
87
. image_backend
85
88
. as_ref ( )
86
- . context ( "Could not detect a supported image backend" ) ?;
89
+ . context ( "No supported image backend detected on your system " ) ?;
87
90
88
91
buf. push_str (
89
92
& image_backend
@@ -92,7 +95,7 @@ impl<W: Write> Printer<W> {
92
95
custom_image,
93
96
self . color_resolution ,
94
97
)
95
- . context ( "Error while drawing image" ) ?,
98
+ . context ( "Failed to render the image in the terminal " ) ?,
96
99
) ;
97
100
} else {
98
101
let mut logo_lines = if let Some ( custom_ascii) = & self . ascii_input {
You can’t perform that action at this time.
0 commit comments