Rod Hynes 5 лет назад
Родитель
Сommit
69e997279b
2 измененных файлов с 17 добавлено и 5 удалено
  1. 16 4
      psiphon/common/errors/errors.go
  2. 1 1
      psiphon/common/stacktrace/stacktrace.go

+ 16 - 4
psiphon/common/errors/errors.go

@@ -36,7 +36,10 @@ import (
 // stack frame information.
 func TraceNew(message string) error {
 	err := fmt.Errorf("%s", message)
-	pc, _, line, _ := runtime.Caller(1)
+	pc, _, line, ok := runtime.Caller(1)
+	if !ok {
+		return fmt.Errorf("[unknown]: %w", err)
+	}
 	return fmt.Errorf("%s#%d: %w", stacktrace.GetFunctionName(pc), line, err)
 }
 
@@ -52,7 +55,10 @@ func BackTraceNew(backTraceFuncName, message string) error {
 // the caller stack frame information.
 func Tracef(format string, args ...interface{}) error {
 	err := fmt.Errorf(format, args...)
-	pc, _, line, _ := runtime.Caller(1)
+	pc, _, line, ok := runtime.Caller(1)
+	if !ok {
+		return fmt.Errorf("[unknown]: %w", err)
+	}
 	return fmt.Errorf("%s#%d: %w", stacktrace.GetFunctionName(pc), line, err)
 }
 
@@ -61,7 +67,10 @@ func Trace(err error) error {
 	if err == nil {
 		return nil
 	}
-	pc, _, line, _ := runtime.Caller(1)
+	pc, _, line, ok := runtime.Caller(1)
+	if !ok {
+		return fmt.Errorf("[unknown]: %w", err)
+	}
 	return fmt.Errorf("%s#%d: %w", stacktrace.GetFunctionName(pc), line, err)
 }
 
@@ -71,7 +80,10 @@ func TraceMsg(err error, message string) error {
 	if err == nil {
 		return nil
 	}
-	pc, _, line, _ := runtime.Caller(1)
+	pc, _, line, ok := runtime.Caller(1)
+	if !ok {
+		return fmt.Errorf("[unknown]: %s: %w", message, err)
+	}
 	return fmt.Errorf("%s#%d: %s: %w", stacktrace.GetFunctionName(pc), line, message, err)
 }
 

+ 1 - 1
psiphon/common/stacktrace/stacktrace.go

@@ -31,7 +31,7 @@ import (
 )
 
 // GetFunctionName is a helper that extracts a simple function name from
-// full name returned byruntime.Func.Name(). This is used to declutter
+// full name returned by runtime.Func.Name(). This is used to declutter
 // error messages containing function names.
 func GetFunctionName(pc uintptr) string {
 	funcName := runtime.FuncForPC(pc).Name()