mirror of
				https://github.com/minio/minio.git
				synced 2025-10-29 15:55:00 -04:00 
			
		
		
		
	trace on New and add read locks
This commit is contained in:
		
							parent
							
								
									d9493909d8
								
							
						
					
					
						commit
						697009c0a1
					
				| @ -60,7 +60,7 @@ type tracePoint struct { | ||||
| 
 | ||||
| // Error implements tracing error functionality. | ||||
| type Error struct { | ||||
| 	lock        sync.Mutex | ||||
| 	lock        sync.RWMutex | ||||
| 	e           error | ||||
| 	sysInfo     map[string]string | ||||
| 	tracePoints []tracePoint | ||||
| @ -71,7 +71,8 @@ type Error struct { | ||||
| // trace the return path with Probe.Trace and finally handle reporting or quitting | ||||
| // at the top level. | ||||
| func New(e error) *Error { | ||||
| 	return &Error{sync.Mutex{}, e, GetSysInfo(), []tracePoint{}} | ||||
| 	Err := Error{sync.RWMutex{}, e, GetSysInfo(), []tracePoint{}} | ||||
| 	return Err.Trace() | ||||
| } | ||||
| 
 | ||||
| // Trace records the point at which it is invoked. Stack traces are important for | ||||
| @ -114,6 +115,9 @@ func (e *Error) Error() string { | ||||
| 
 | ||||
| // String returns error message. | ||||
| func (e *Error) String() string { | ||||
| 	e.lock.RLock() | ||||
| 	defer e.lock.RUnlock() | ||||
| 
 | ||||
| 	trace := e.e.Error() + "\n" | ||||
| 	for i, tp := range e.tracePoints { | ||||
| 		if len(tp.Env) > 0 { | ||||
| @ -135,6 +139,9 @@ func (e *Error) String() string { | ||||
| 
 | ||||
| // JSON returns JSON formated error trace. | ||||
| func (e *Error) JSON() string { | ||||
| 	e.lock.RLock() | ||||
| 	defer e.lock.RUnlock() | ||||
| 
 | ||||
| 	anonError := struct { | ||||
| 		SysInfo     map[string]string | ||||
| 		TracePoints []tracePoint | ||||
| @ -153,5 +160,6 @@ func (e *Error) JSON() string { | ||||
| 
 | ||||
| // ToError returns original emnedded error. | ||||
| func (e *Error) ToError() error { | ||||
| 	// No need to lock. "e.e" is set once during New and never changed. | ||||
| 	return e.e | ||||
| } | ||||
|  | ||||
| @ -16,7 +16,6 @@ | ||||
| package probe | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"testing" | ||||
| ) | ||||
| @ -33,8 +32,14 @@ func TestProbe(t *testing.T) { | ||||
| 	if es == nil { | ||||
| 		t.Fail() | ||||
| 	} | ||||
| 	es.Trace() | ||||
| 	fmt.Println(es) | ||||
| 	// fmt.Println(es.JSON()) | ||||
| 	// fmt.Println(es.ToError()) | ||||
| 
 | ||||
| 	newES := es.Trace() | ||||
| 	if newES == nil { | ||||
| 		t.Fail() | ||||
| 	} | ||||
| 	/* | ||||
| 		fmt.Println(es) | ||||
| 		fmt.Println(es.JSON()) | ||||
| 		fmt.Println(es.ToError()) | ||||
| 	*/ | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user