Skip to content

Commit 4a6e83c

Browse files
committed
Improve lints.
- When including an error in a lint, don't just include the top-level error, but also the causes. - Fixes #110.
1 parent 140fd7e commit 4a6e83c

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ fn error_chain(err: &anyhow::Error) -> Vec<String> {
189189
errs
190190
}
191191

192+
fn error_chain_display(err: &anyhow::Error) -> String {
193+
error_chain(err).join(", because ")
194+
}
195+
192196
// Generate macros for working with lints.
193197
//
194198
// Note: $dollar is a hack, which we use because nested macros with
@@ -1727,7 +1731,8 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17271731
let usable = 'done : loop {
17281732
match cert.with_policy(&*P.read().unwrap(), None) {
17291733
Err(err) => {
1730-
lint(&format!("Policy rejects {}: {}", cert.keyid(), err));
1734+
lint(&format!("Policy rejects {}: {}",
1735+
cert.keyid(), error_chain_display(&err)));
17311736
break 'done false;
17321737
}
17331738
Ok(vc) => {
@@ -1757,10 +1762,10 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17571762
if let Some(e) = vc.primary_key().key_expiration_time() {
17581763
if e <= SystemTime::now() {
17591764
lint(&format!("The certificate is expired: {}",
1760-
err));
1765+
error_chain_display(&err)));
17611766
} else {
17621767
lint(&format!("The certificate is not live: {}",
1763-
err));
1768+
error_chain_display(&err)));
17641769
}
17651770
}
17661771
}
@@ -1774,7 +1779,7 @@ fn _pgpPubKeyLint(pkts: *const c_char,
17741779
match ka.with_policy(&*P.read().unwrap(), None) {
17751780
Err(err) => {
17761781
lint(&format!("Policy rejects subkey {}: {}",
1777-
keyid, err));
1782+
keyid, error_chain_display(&err)));
17781783
continue;
17791784
}
17801785
Ok(ka) => {
@@ -1814,10 +1819,10 @@ fn _pgpPubKeyLint(pkts: *const c_char,
18141819
if let Some(e) = ka.key_expiration_time() {
18151820
if e <= SystemTime::now() {
18161821
lint(&format!("Subkey {} is expired: {}",
1817-
keyid, err));
1822+
keyid, error_chain_display(&err)));
18181823
} else {
18191824
lint(&format!("Subkey {} is not live: {}",
1820-
keyid, err));
1825+
keyid, error_chain_display(&err)));
18211826
}
18221827
}
18231828
continue;

0 commit comments

Comments
 (0)