Move telemetry handling to the tracing-specific main function.
This is so main_body can exit with an error at any time without missing the shutdown_telemetry function. This does not catch panics.
This commit is contained in:
parent
dae46adc12
commit
e5e5120a10
35
src/main.rs
35
src/main.rs
@ -9,11 +9,12 @@ use organic::compare_document;
|
|||||||
use organic::emacs_parse_org_document;
|
use organic::emacs_parse_org_document;
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
use organic::parser::sexp::sexp_with_padding;
|
use organic::parser::sexp::sexp_with_padding;
|
||||||
#[cfg(feature = "tracing")]
|
|
||||||
use tracing::span;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
use crate::init_tracing::init_telemetry;
|
use crate::init_tracing::init_telemetry;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
use crate::init_tracing::shutdown_telemetry;
|
use crate::init_tracing::shutdown_telemetry;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
mod init_tracing;
|
mod init_tracing;
|
||||||
|
|
||||||
#[cfg(not(feature = "tracing"))]
|
#[cfg(not(feature = "tracing"))]
|
||||||
@ -24,28 +25,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let rt = tokio::runtime::Runtime::new()?;
|
let rt = tokio::runtime::Runtime::new()?;
|
||||||
let result = rt.block_on(async { main_body() });
|
let result = rt.block_on(async {
|
||||||
|
init_telemetry()?;
|
||||||
|
let main_body_result = main_body();
|
||||||
|
shutdown_telemetry()?;
|
||||||
|
main_body_result
|
||||||
|
});
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
init_telemetry()?;
|
run_compare(
|
||||||
let compare_result = {
|
std::env::args()
|
||||||
#[cfg(feature = "tracing")]
|
.nth(1)
|
||||||
let span = span!(tracing::Level::DEBUG, "run_compare");
|
.expect("Pass a single file into this script."),
|
||||||
#[cfg(feature = "tracing")]
|
)
|
||||||
let _enter = span.enter();
|
|
||||||
|
|
||||||
run_compare(
|
|
||||||
std::env::args()
|
|
||||||
.nth(1)
|
|
||||||
.expect("Pass a single file into this script."),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
shutdown_telemetry()?;
|
|
||||||
compare_result?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "compare")]
|
#[cfg(feature = "compare")]
|
||||||
|
@ -241,18 +241,7 @@ fn plain_list_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
|
|||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
fn plain_list_item_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
fn plain_list_item_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
let current_item_indent_level: &usize =
|
recognize(parser_with_context!(line_indented_lte)(context))(input)
|
||||||
get_context_item_indent(context).ok_or(nom::Err::Error(CustomError::MyError(MyError(
|
|
||||||
"Not inside a plain list item",
|
|
||||||
))))?;
|
|
||||||
let plain_list_item_matcher = parser_with_context!(plain_list_item)(context);
|
|
||||||
let line_indented_lte_matcher = parser_with_context!(line_indented_lte)(context);
|
|
||||||
alt((
|
|
||||||
recognize(verify(plain_list_item_matcher, |pli| {
|
|
||||||
pli.indentation <= *current_item_indent_level
|
|
||||||
})),
|
|
||||||
recognize(line_indented_lte_matcher),
|
|
||||||
))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user