Add --crash flag to crash and print stack trace on panic
This commit is contained in:
		
							parent
							
								
									ac2db05d06
								
							
						
					
					
						commit
						861d6af1d7
					
				@ -41,6 +41,7 @@ type environment struct {
 | 
				
			|||||||
		logDirectory string
 | 
							logDirectory string
 | 
				
			||||||
		configFile   string
 | 
							configFile   string
 | 
				
			||||||
		verbose      bool
 | 
							verbose      bool
 | 
				
			||||||
 | 
							crash        bool
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// running stores whether the environment is currently running.
 | 
						// running stores whether the environment is currently running.
 | 
				
			||||||
@ -282,7 +283,12 @@ func (this *environment) runRunnable(ctx context.Context, actor Runnable) (stopE
 | 
				
			|||||||
	for {
 | 
						for {
 | 
				
			||||||
		// run actor
 | 
							// run actor
 | 
				
			||||||
		lastStart := time.Now()
 | 
							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
 | 
							// detect context cancellation
 | 
				
			||||||
		if ctxErr := ctx.Err(); ctxErr != nil {
 | 
							if ctxErr := ctx.Err(); ctxErr != nil {
 | 
				
			||||||
 | 
				
			|||||||
@ -24,6 +24,7 @@ func (this *environment) phase10FlagParsing() bool {
 | 
				
			|||||||
	flagLogDirectory  := set.Flag('l', "log-directory", "Write logs to the specified directory", cli.ValString)
 | 
						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)
 | 
						flagConfigFile    := set.Flag('c', "config-file",   "Use this configuration file", cli.ValString)
 | 
				
			||||||
	flagVerbose       := set.Flag('v', "verbose",       "Enable verbose output/logging", nil)
 | 
						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
 | 
						// ask actors to add flags
 | 
				
			||||||
	actors, done := this.actors.RBorrow()
 | 
						actors, done := this.actors.RBorrow()
 | 
				
			||||||
@ -60,6 +61,9 @@ func (this *environment) phase10FlagParsing() bool {
 | 
				
			|||||||
	if _, ok := flagVerbose.First(); ok {
 | 
						if _, ok := flagVerbose.First(); ok {
 | 
				
			||||||
		this.flags.verbose = true
 | 
							this.flags.verbose = true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if _, ok := flagCrash.First(); ok {
 | 
				
			||||||
 | 
							this.flags.crash = true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user