github.com/Rookout/GoSDK@v0.1.48/pkg/processor/namespaces/stack_namespace.go (about) 1 package namespaces 2 3 import ( 4 "container/list" 5 "strconv" 6 7 "github.com/Rookout/GoSDK/pkg/rookoutErrors" 8 "github.com/Rookout/GoSDK/pkg/services/collection" 9 ) 10 11 const defaultTracebackDepth = 1000 12 13 type StackNamespace struct { 14 collectionService *collection.CollectionService 15 } 16 17 func NewStackNamespace(collectionService *collection.CollectionService) *StackNamespace { 18 return &StackNamespace{ 19 collectionService: collectionService, 20 } 21 } 22 23 func (s *StackNamespace) ReadKey(_ interface{}) (Namespace, rookoutErrors.RookoutError) { 24 return nil, rookoutErrors.NewNotImplemented() 25 } 26 27 func (s *StackNamespace) CallMethod(name string, args string) (Namespace, rookoutErrors.RookoutError) { 28 switch name { 29 case "traceback": 30 return s.Traceback(args) 31 case "frames": 32 return nil, rookoutErrors.NewNotImplemented() 33 } 34 return nil, rookoutErrors.NewRookMethodNotFound(name) 35 } 36 37 func (s *StackNamespace) Traceback(args string) (Namespace, rookoutErrors.RookoutError) { 38 depth := 0 39 if len(args) > 0 { 40 var err error 41 depth, err = strconv.Atoi(args) 42 if err != nil { 43 return nil, rookoutErrors.NewRookInvalidMethodArguments("traceback()", args) 44 } 45 } else { 46 depth = defaultTracebackDepth 47 } 48 49 l := list.New() 50 for i, stackFrame := range s.collectionService.StackTraceElements { 51 if i > depth { 52 break 53 } 54 55 containerNamespace := NewEmptyContainerNamespace() 56 _ = containerNamespace.WriteAttribute("filename", NewGoObjectNamespace(stackFrame.File)) 57 _ = containerNamespace.WriteAttribute("module", NewGoObjectNamespace(stackFrame.File)) 58 _ = containerNamespace.WriteAttribute("line", NewGoObjectNamespace(stackFrame.Line)) 59 _ = containerNamespace.WriteAttribute("function", NewGoObjectNamespace(stackFrame.Function)) 60 61 l.PushBack(containerNamespace) 62 } 63 64 return NewTracebackNamespace(s.collectionService.StackTraceElements, depth), nil 65 } 66 67 func (s *StackNamespace) ReadAttribute(_ string) (Namespace, rookoutErrors.RookoutError) { 68 return nil, rookoutErrors.NewNotImplemented() 69 } 70 71 func (s *StackNamespace) WriteAttribute(_ string, _ Namespace) rookoutErrors.RookoutError { 72 return rookoutErrors.NewNotImplemented() 73 } 74 75 func (s *StackNamespace) GetObject() interface{} { 76 return nil 77 } 78 79 func (s *StackNamespace) Serialize(serializer Serializer) { 80 dumpError(serializer, rookoutErrors.NewNotImplemented()) 81 }