mirror of https://github.com/Xhofe/alist
				
				
				
			feat(task): print stack trace if panic
							parent
							
								
									75fd0ee185
								
							
						
					
					
						commit
						86a773674a
					
				| 
						 | 
				
			
			@ -3,6 +3,7 @@ package task
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"runtime"
 | 
			
		||||
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
	log "github.com/sirupsen/logrus"
 | 
			
		||||
| 
						 | 
				
			
			@ -63,11 +64,17 @@ func (t Task[K]) GetErrMsg() string {
 | 
			
		|||
	return t.Error.Error()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getCurrentGoroutineStack() string {
 | 
			
		||||
	buf := make([]byte, 1<<16)
 | 
			
		||||
	n := runtime.Stack(buf, false)
 | 
			
		||||
	return string(buf[:n])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t *Task[K]) run() {
 | 
			
		||||
	t.state = RUNNING
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if err := recover(); err != nil {
 | 
			
		||||
			log.Errorf("error [%+v] while run task [%s]", err, t.Name)
 | 
			
		||||
			log.Errorf("error [%s] while run task [%s],stack trace:\n%s", err, t.Name, getCurrentGoroutineStack())
 | 
			
		||||
			t.Error = errors.Errorf("panic: %+v", err)
 | 
			
		||||
			t.state = ERRORED
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue