|
|
@ -23,6 +23,7 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
|
|
|
|
"sync" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Error is the iodine error which contains a pointer to the original error
|
|
|
|
// Error is the iodine error which contains a pointer to the original error
|
|
|
@ -42,6 +43,35 @@ type StackEntry struct { |
|
|
|
Data map[string]string |
|
|
|
Data map[string]string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var globalState = struct { |
|
|
|
|
|
|
|
sync.RWMutex |
|
|
|
|
|
|
|
m map[string]string |
|
|
|
|
|
|
|
}{m: make(map[string]string)} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func SetGlobalState(key, value string) { |
|
|
|
|
|
|
|
globalState.Lock() |
|
|
|
|
|
|
|
globalState.m[key] = value |
|
|
|
|
|
|
|
globalState.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ClearGlobalState() { |
|
|
|
|
|
|
|
globalState.Lock() |
|
|
|
|
|
|
|
for k, _ := range globalState.m { |
|
|
|
|
|
|
|
delete(globalState.m, k) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
globalState.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetGlobalState() map[string]string { |
|
|
|
|
|
|
|
result := make(map[string]string) |
|
|
|
|
|
|
|
globalState.RLock() |
|
|
|
|
|
|
|
for k, v := range globalState.m { |
|
|
|
|
|
|
|
result[k] = v |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
globalState.RUnlock() |
|
|
|
|
|
|
|
return result |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Wrap an error, turning it into an iodine error.
|
|
|
|
// Wrap an error, turning it into an iodine error.
|
|
|
|
// Adds an initial stack trace.
|
|
|
|
// Adds an initial stack trace.
|
|
|
|
func New(err error, data map[string]string) *Error { |
|
|
|
func New(err error, data map[string]string) *Error { |
|
|
@ -63,18 +93,17 @@ func createStackEntry() StackEntry { |
|
|
|
Host: host, |
|
|
|
Host: host, |
|
|
|
File: file, |
|
|
|
File: file, |
|
|
|
Line: line, |
|
|
|
Line: line, |
|
|
|
Data: make(map[string]string), |
|
|
|
Data: GetGlobalState(), |
|
|
|
} |
|
|
|
} |
|
|
|
return entry |
|
|
|
return entry |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Annotate an error with a stack entry and returns itself
|
|
|
|
// Annotate an error with a stack entry and returns itself
|
|
|
|
func (err *Error) Annotate(info map[string]string) *Error { |
|
|
|
func (err *Error) Annotate(info map[string]string) *Error { |
|
|
|
data := make(map[string]string) |
|
|
|
entry := createStackEntry() |
|
|
|
for k, v := range info { |
|
|
|
for k, v := range info { |
|
|
|
data[k] = v |
|
|
|
entry.Data[k] = v |
|
|
|
} |
|
|
|
} |
|
|
|
entry := createStackEntry() |
|
|
|
|
|
|
|
err.Stack = append(err.Stack, entry) |
|
|
|
err.Stack = append(err.Stack, entry) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|