Allow hooks to error (#11615)

Allow hooks to return errors. 

We should do this before introducing more hook types, or we'll have to
migrate them all.
This commit is contained in:
gt-oai
2026-02-16 14:11:05 +00:00
committed by GitHub
parent 825a4af42f
commit b3095679ed
6 changed files with 251 additions and 43 deletions

View File

@@ -6,8 +6,8 @@ use serde::Serialize;
use crate::Hook;
use crate::HookEvent;
use crate::HookOutcome;
use crate::HookPayload;
use crate::HookResult;
use crate::command_from_argv;
/// Legacy notify payload appended as the final argv argument for backward compatibility.
@@ -48,12 +48,13 @@ pub fn legacy_notify_json(hook_event: &HookEvent, cwd: &Path) -> Result<String,
pub fn notify_hook(argv: Vec<String>) -> Hook {
let argv = Arc::new(argv);
Hook {
name: "legacy_notify".to_string(),
func: Arc::new(move |payload: &HookPayload| {
let argv = Arc::clone(&argv);
Box::pin(async move {
let mut command = match command_from_argv(&argv) {
Some(command) => command,
None => return HookOutcome::Continue,
None => return HookResult::Success,
};
if let Ok(notify_payload) = legacy_notify_json(&payload.hook_event, &payload.cwd) {
command.arg(notify_payload);
@@ -65,8 +66,10 @@ pub fn notify_hook(argv: Vec<String>) -> Hook {
.stdout(Stdio::null())
.stderr(Stdio::null());
let _ = command.spawn();
HookOutcome::Continue
match command.spawn() {
Ok(_) => HookResult::Success,
Err(err) => HookResult::FailedContinue(err.into()),
}
})
}),
}