github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/common/debug.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package common
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  	"runtime"
    18  	"runtime/debug"
    19  	"strings"
    20  )
    21  
    22  // Report gives off a warning requesting the user to submit an issue to the github tracker.
    23  func Report(extra ...interface{}) {
    24  	fmt.Fprintln(os.Stderr, "You've encountered a sought after, hard to reproduce bug. Please report this to the developers <3 https://github.com/Sberex/go-sberex/issues")
    25  	fmt.Fprintln(os.Stderr, extra...)
    26  
    27  	_, file, line, _ := runtime.Caller(1)
    28  	fmt.Fprintf(os.Stderr, "%v:%v\n", file, line)
    29  
    30  	debug.PrintStack()
    31  
    32  	fmt.Fprintln(os.Stderr, "#### BUG! PLEASE REPORT ####")
    33  }
    34  
    35  // PrintDepricationWarning prinst the given string in a box using fmt.Println.
    36  func PrintDepricationWarning(str string) {
    37  	line := strings.Repeat("#", len(str)+4)
    38  	emptyLine := strings.Repeat(" ", len(str))
    39  	fmt.Printf(`
    40  %s
    41  # %s #
    42  # %s #
    43  # %s #
    44  %s
    45  
    46  `, line, emptyLine, str, emptyLine, line)
    47  }