fix: replace unwrap() with graceful error in scheduler execute_job#7436
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents the scheduler’s execute_job path from panicking when a recipe loaded from YAML has neither prompt nor instructions, returning a descriptive anyhow error instead.
Changes:
- Replaces an
Option::unwrap()onprompt/instructionswith anok_or_else(...)?error inexecute_job.
crates/goose/src/scheduler.rs
Outdated
| .as_ref() | ||
| .or(recipe.instructions.as_ref()) |
There was a problem hiding this comment.
Consider reusing the existing recipe validation helper (e.g., validate_recipe_template_from_content / validate_prompt_or_instructions) instead of a local Option check so scheduler behavior stays consistent (it also treats empty/whitespace-only values as invalid and centralizes the error message).
| .as_ref() | |
| .or(recipe.instructions.as_ref()) | |
| .as_deref() | |
| .filter(|s| !s.trim().is_empty()) | |
| .or_else(|| { | |
| recipe | |
| .instructions | |
| .as_deref() | |
| .filter(|s| !s.trim().is_empty()) | |
| }) |
There was a problem hiding this comment.
Done — updated to use .as_deref().filter(|s| \!s.trim().is_empty()) consistent with validate_prompt_or_instructions in validate_recipe.rs. Also aligned the error message.
crates/goose/src/scheduler.rs
Outdated
| .as_ref() | ||
| .or(recipe.instructions.as_ref()) | ||
| .unwrap(); | ||
| .ok_or_else(|| anyhow!("Recipe must have either 'prompt' or 'instructions' set"))?; |
There was a problem hiding this comment.
Please add a regression test covering a recipe file with neither prompt nor instructions to ensure this path returns a user-facing error (and never panics) when a scheduled job executes.
There was a problem hiding this comment.
Added test_job_with_no_prompt_does_not_panic — creates a recipe YAML with neither prompt nor instructions, schedules it, and asserts the scheduler handles it gracefully without panicking.
b7286f9 to
a3415d0
Compare
…ic on missing prompt/instructions Signed-off-by: Marlon Barreto <[email protected]>
a3415d0 to
802d96c
Compare
…tructions - Use as_deref().filter() consistent with validate_prompt_or_instructions - Add test_job_with_no_prompt_does_not_panic regression test Signed-off-by: Marlon Barreto <[email protected]>
|
Hey @DOsinga — friendly ping on this one. The fix is minimal (adds a |
…m-cache * 'main' of github.com:block/goose: fix: replace unwrap() with graceful error in scheduler execute_job (#7436) fix: Dictation API error message shows incorrect limit (#7423) fix(acp): Use ACP schema types for session/list (#7409) fix(desktop): make bundle and updater asset naming configurable (#7337) fix(openai): preserve order in Responses API history (#7500) Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485) feat(ui): implement fullscreen and pip display modes for MCP Apps (#7312) Disable tool pair summarization (#7481)
…lock#7436) Signed-off-by: Marlon Barreto <[email protected]>
…patible * origin/main: (70 commits) feat: allow goose askai bot to search goose codebase (#7508) Revert "Reapply "fix: prevent crashes in long-running Electron sessions"" Reapply "fix: prevent crashes in long-running Electron sessions" Revert "fix: prevent crashes in long-running Electron sessions" fix: replace unwrap() with graceful error in scheduler execute_job (#7436) fix: Dictation API error message shows incorrect limit (#7423) fix(acp): Use ACP schema types for session/list (#7409) fix(desktop): make bundle and updater asset naming configurable (#7337) fix(openai): preserve order in Responses API history (#7500) Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485) feat(ui): implement fullscreen and pip display modes for MCP Apps (#7312) fix: prevent crashes in long-running Electron sessions Disable tool pair summarization (#7481) fix: New Recipe Warning does not close on cancel (#7524) The client is not the source of truth (#7438) feat: support Anthropic adaptive thinking (#7356) copilot instructions: reword no prerelease docs (#7101) fix(acp): don't fail session creation when model listing is unavailable (#7484) feat: simplify developer extension (#7466) feat: add goose-powered release notes generator workflow (#7503) ... # Conflicts: # Cargo.lock
…m-extension-pr * origin/main: Update CODEOWNERS for team restructuring (#7574) Add snapshot test with platform extensions (#7573) Handle Bedrock 'prompt is too long' error (#7550) feat: make pctx/Code Mode an optional dependency via 'code-mode' feature (#7567) chore(release): release version 1.26.0 (minor) (#7512) feat: allow goose askai bot to search goose codebase (#7508) Revert "Reapply "fix: prevent crashes in long-running Electron sessions"" Reapply "fix: prevent crashes in long-running Electron sessions" Revert "fix: prevent crashes in long-running Electron sessions" fix: replace unwrap() with graceful error in scheduler execute_job (#7436) fix: Dictation API error message shows incorrect limit (#7423) fix(acp): Use ACP schema types for session/list (#7409) fix(desktop): make bundle and updater asset naming configurable (#7337) fix(openai): preserve order in Responses API history (#7500) Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485) fix: prevent crashes in long-running Electron sessions
…lock#7436) Signed-off-by: Marlon Barreto <[email protected]>
Summary
.unwrap()with.ok_or_else()inexecute_job(scheduler.rs line ~785) to prevent a panic when a recipe YAML has neitherpromptnorinstructionssetFixes
Context
When a recipe is loaded directly from YAML (bypassing
RecipeBuildervalidation), bothpromptandinstructionscan beNone. The.unwrap()on theOptionchain causes a panic with no error message. This replaces it with a descriptive error that propagates through theResultreturn type.Test plan