func GetRecoveryOpts()

in grpc/common/recoveryOpts.go [39:84]


func GetRecoveryOpts() []recovery.Option {
	getFileAndLineNum := func(p any) (err error) {
		// get the file and line number where the panic occurred
		// panic is terminated by custom recovery function and program continues
		stack := debug.Stack()
		file, linenum := ParseStack(string(stack))

		// TODO: allow users to customize or we auto populate this repo path.
		base := "https://msazure.visualstudio.com/CloudNativeCompute/_git/aks-rp"
		path := file
		if strings.Contains(path, "aks-rp") {
			filepath := strings.SplitN(file, "aks-rp", 2)
			path = filepath[1]
		}

		version := "GB" + os.Getenv("AKS_BIN_VERSION_GITBRANCH")

		params := url.Values{}
		params.Add("path", path)

		params.Add("version", version)
		params.Add("line", linenum)

		query, err := url.QueryUnescape(params.Encode())
		if err != nil {
			fmt.Println(err)
			// skip query if url.QueryUnescape() fails
			query = ""
		}

		url := ""
		// url is not generated as file is not in aks-rp
		if path != file {
			url = base + "?" + query
		}

		// format the error message with the file and line number
		return status.Errorf(codes.Internal, "panic_message: %v, file: %s, line: %s, url: %s", p, file, linenum, url)
	}
	opts := []recovery.Option{
		recovery.WithRecoveryHandler(getFileAndLineNum),
	}

	return opts

}