From 97da96df6fccbf2aefd0bee24a34787516e1d678 Mon Sep 17 00:00:00 2001 From: Abeeujah Date: Sat, 2 Nov 2024 13:02:35 +0100 Subject: [PATCH] Error handling to improve function ergonomics --- eipw-lint/src/lints/markdown/headings_only.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/eipw-lint/src/lints/markdown/headings_only.rs b/eipw-lint/src/lints/markdown/headings_only.rs index 66d176d4..b891a28b 100644 --- a/eipw-lint/src/lints/markdown/headings_only.rs +++ b/eipw-lint/src/lints/markdown/headings_only.rs @@ -14,15 +14,11 @@ pub struct HeadingsOnly; impl Lint for HeadingsOnly { fn lint<'a>(&self, slug: &'a str, ctx: &crate::lints::Context<'a, '_>) -> Result<(), Error> { - let second = ctx - .body() - .descendants() - .nth(1) - .expect("cannot submit an empty proposal") - .data - .borrow() - .to_owned() - .value; + let annotation_type = Level::Error; + let second = match ctx.body().descendants().nth(1) { + Some(el) => el.data.borrow().to_owned().value, + None => return ctx.report(annotation_type.title("Cannot submit an empty proposal")), + }; match second { NodeValue::Heading(_) => Ok(()), _ => {