From 861d6af1d7d5f373d7f42df1c0ec622b1137cfd2 Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Tue, 8 Apr 2025 10:29:27 -0400 Subject: [PATCH] Add --crash flag to crash and print stack trace on panic --- environment.go | 8 +++++++- phases.go | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/environment.go b/environment.go index 7cdcebc..ec412a5 100644 --- a/environment.go +++ b/environment.go @@ -41,6 +41,7 @@ type environment struct { logDirectory string configFile string verbose bool + crash bool } // running stores whether the environment is currently running. @@ -282,7 +283,12 @@ func (this *environment) runRunnable(ctx context.Context, actor Runnable) (stopE for { // run actor lastStart := time.Now() - err := panicWrapCtx(ctx, actor.Run) + var err error + if this.flags.crash { + err = actor.Run(ctx) + } else { + err = panicWrapCtx(ctx, actor.Run) + } // detect context cancellation if ctxErr := ctx.Err(); ctxErr != nil { diff --git a/phases.go b/phases.go index 1b6a298..73d805f 100644 --- a/phases.go +++ b/phases.go @@ -24,6 +24,7 @@ func (this *environment) phase10FlagParsing() bool { flagLogDirectory := set.Flag('l', "log-directory", "Write logs to the specified directory", cli.ValString) flagConfigFile := set.Flag('c', "config-file", "Use this configuration file", cli.ValString) flagVerbose := set.Flag('v', "verbose", "Enable verbose output/logging", nil) + flagCrash := set.Flag(0, "crash", "Crash when an actor panics", nil) // ask actors to add flags actors, done := this.actors.RBorrow() @@ -60,6 +61,9 @@ func (this *environment) phase10FlagParsing() bool { if _, ok := flagVerbose.First(); ok { this.flags.verbose = true } + if _, ok := flagCrash.First(); ok { + this.flags.crash = true + } return true }