Skip to content

Commit

Permalink
Add Register Empty Call Location
Browse files Browse the repository at this point in the history
  • Loading branch information
tung.tq committed Oct 18, 2023
1 parent ad50b4f commit 116b226
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions svloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ func (s *registeredService) newServiceSlow(unv *Universe, callLoc string) any {
return s.svc
}

func (u *Universe) printGetCallTrace(problem string, callLoc string) {
func printSeparateLine() {
fmt.Println("==========================================================")
}

func (u *Universe) printGetCallTrace(problem string, callLoc string) {
printSeparateLine()
fmt.Printf("%s:\n", problem)

if callLoc != "" {
Expand All @@ -157,7 +161,7 @@ func (u *Universe) printGetCallTrace(problem string, callLoc string) {
fmt.Println("\t" + reg.getCallLocation)
}

fmt.Println("==========================================================")
printSeparateLine()
}

func (u *Universe) detectedCircularDependency(newKey any, callLoc string) bool {
Expand Down Expand Up @@ -460,12 +464,16 @@ func RegisterSimple[T any]() *Locator[T] {
func RegisterEmpty[T any]() *Locator[T] {
checkAllowRegistering()

callLoc := getCallerLocation()

key := new(int)
var val *T

return &Locator[T]{
key: key,
newFn: func(unv *Universe) any {
printSeparateLine()
fmt.Println("'RegisterEmpty' location:", callLoc)
unv.printGetCallTrace("Get call stacktrace", "")
panic(
fmt.Sprintf(
Expand All @@ -474,7 +482,7 @@ func RegisterEmpty[T any]() *Locator[T] {
),
)
},
registerLoc: getCallerLocation(),
registerLoc: callLoc,
}
}

Expand Down

0 comments on commit 116b226

Please sign in to comment.