summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/core/libimagrt/src/application.rs22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/core/libimagrt/src/application.rs b/lib/core/libimagrt/src/application.rs
index 74ad4b68..e1de1fe2 100644
--- a/lib/core/libimagrt/src/application.rs
+++ b/lib/core/libimagrt/src/application.rs
@@ -37,34 +37,24 @@ macro_rules! simple_imag_application_binary {
extern crate failure;
extern crate $application_library;
- use failure::{Error, Fallible as Result};
-
+ use failure::{Error, Fallible as Result, ResultExt};
+
fn main() {
use libimagerror::trace::MapErrTrace;
use libimagrt::application::ImagApplication;
use libimagrt::setup::generate_runtime_setup;
use $application_library::$application_implementor;
-
+
let version = make_imag_version!();
let rt = generate_runtime_setup($application_implementor::name(),
&version,
$application_implementor::description(),
$application_implementor::build_cli);
- // The error context must have a 'static lifetime
- // Therefore, the easiest, safe, but hacky way to achieve this
- // is to allocate a string, which is then forgotten to
- // leak memory and return it's contents as a &'static str
- // Because this is the very end of the application and only
- // happens once, it should have no impact whatsoever
- let error_context: &'static str = Box::leak(
- format!("Failed to run {}", $application_implementor::name())
- .into_boxed_str()
- );
$application_implementor::run(rt)
- .map_err(|e| e.context(error_context))
- .map_err(Error::from)
- .map_err_trace_exit_unwrap();
+ .context(format!("Failed to run {}", $application_implementor::name()))
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap();
}
};
}