当前位置: 首页>>代码示例>>Golang>>正文


Golang debug.PrintStack函数代码示例

本文整理汇总了Golang中runtime/debug.PrintStack函数的典型用法代码示例。如果您正苦于以下问题:Golang PrintStack函数的具体用法?Golang PrintStack怎么用?Golang PrintStack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PrintStack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newGameStateWithAppliedMove

func (initialState *GameState) newGameStateWithAppliedMove(applyMe *Move) (*GameState, error) {
	occupiedHoles := make([]Coordinate, len(initialState.occupiedHoles))
	copy(occupiedHoles, initialState.occupiedHoles)

	occupiedHoles, err := remove(occupiedHoles, applyMe.From())
	if err != nil {
		debug.PrintStack()
		return nil, errors.New("Move is not consistent with game state: 'from' hole was unoccupied.")
	}

	occupiedHoles, err = remove(occupiedHoles, applyMe.Jumped())
	if err != nil {
		debug.PrintStack()
		return nil, errors.New("Move is not consistent with game state: jumped hole was unoccupied.")
	}

	if contains(occupiedHoles, *applyMe.To()) {
		debug.PrintStack()
		fmt.Println("error when applying", applyMe, "to", initialState)
		return nil, errors.New("Move is not consistent with game state: 'to' hole was occupied.")
	}

	if applyMe.To().Row() > initialState.rowCount || applyMe.To().Row() < 1 {
		errors.New(fmt.Sprintf("Move is not legal because the 'to' hole does not exist: %s", applyMe.To()))
	}

	occupiedHoles = append(occupiedHoles, *applyMe.To())

	return &GameState{initialState.rowCount, occupiedHoles}, nil
}
开发者ID:wolever,项目名称:peg-performance,代码行数:30,代码来源:gamestate.go

示例2: Select

func (b *fanOutTestBuffer) Select(user string, from, to, expectedFromIndex, expectedToIndex uint64, expected ...string) {
	signals, fromIndex, toIndex, err := b.buffer.SelectForwards(types.Id(types.NewUserId(user, "test")), from, to)
	if err != nil {
		debug.PrintStack()
		b.t.Fatal("failed to get signal range: ", err)
	}
	if len(signals) != len(expected) {
		debug.PrintStack()
		b.t.Fatalf("invalid signal count, expected %d but got %d", len(expected), len(signals))
	}
	if expectedFromIndex != fromIndex {
		debug.PrintStack()
		b.t.Fatalf("invalid from index, expected %d but got %d", expectedFromIndex, fromIndex)
	}
	if expectedToIndex != toIndex {
		debug.PrintStack()
		b.t.Fatalf("invalid to index, expected %d but got %d", expectedToIndex, toIndex)
	}
	for i, signal := range signals {
		if signal.EventId.Id != expected[i] {
			debug.PrintStack()
			b.t.Fatalf("invalid event id: expected %s, got %s", expected[i], signal.EventId.Id)
		}
	}
}
开发者ID:Rugvip,项目名称:bullettime,代码行数:25,代码来源:fanoutstream_test.go

示例3: Write

func Write(conn net.Conn, filename string, contents string, exptime int) int64 {
	reader := bufio.NewReader(conn)
	fmt.Fprintf(conn, "write %v %v %v\r\n%v\r\n", filename, len(contents), exptime, contents)
	resp, ok := reader.ReadBytes('\n')
	debugFsnTest(fmt.Sprintf("Write got response:%v\n", string(resp)))
	if ok != nil {
		fmt.Fprintf(os.Stderr, "Error in reading from socket in Write\n")
		fmt.Printf("Error in reading from socket in Write\n")
		debug.PrintStack()
		os.Exit(2)
	}
	arr := strings.Fields(string(resp))
	if arr[0] != "OK" {
		fmt.Fprintf(os.Stderr, "Expected: %v found: %v in Write 1\n", "OK", arr[0])
		fmt.Printf("Expected: %v found: %v in Write 1\n", "OK", arr[0])
		debug.PrintStack()
		os.Exit(2)
	}
	version, err := strconv.ParseInt(arr[1], 10, 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Non-numeric version found in Write")
		fmt.Printf("Non-numeric version found in Write")
		debug.PrintStack()
		os.Exit(2)
	}
	return version
}
开发者ID:samkit993,项目名称:cs733,代码行数:27,代码来源:fsnode_test.go

示例4: CasFailure

func CasFailure(conn net.Conn, filename string, contents string, incorrect_version int64, correct_version int64, exptime int, errstr string) {
	reader := bufio.NewReader(conn)
	fmt.Fprintf(conn, "cas %v %v %v %v\r\n%v\r\n", filename, incorrect_version, len(contents), exptime, contents)
	resp, ok := reader.ReadBytes('\n')
	if ok != nil {
		fmt.Fprintf(os.Stderr, "Error in reading from socket in CasFailure\n")
		fmt.Printf("Error in reading from socket in CasFailure\n")
		debug.PrintStack()
		os.Exit(2)
	}
	arr := strings.Fields(string(resp))
	//expect(t, arr[0], errstr)
	if arr[0] != errstr {
		fmt.Printf("Expected: %v found: %v in CasFailure\n", errstr, arr[0])
		debug.PrintStack()
		os.Exit(2)
	}
	//expect(t, arr[1], fmt.Sprintf("%v",version))
	if arr[1] != fmt.Sprintf("%v", correct_version) {
		fmt.Fprintf(os.Stderr, "Expected: %v found: %v in CasFailure\n", fmt.Sprintf("%v", correct_version), arr[1])
		fmt.Printf("Expected: %v found: %v in CasFailure\n", fmt.Sprintf("%v", correct_version), arr[1])
		debug.PrintStack()
		os.Exit(2)
	}
}
开发者ID:samkit993,项目名称:cs733,代码行数:25,代码来源:fsnode_test.go

示例5: CasSuccess

func CasSuccess(conn net.Conn, filename string, contents string, version int64, exptime int) int64 {
	reader := bufio.NewReader(conn)
	fmt.Fprintf(conn, "cas %v %v %v %v\r\n%v\r\n", filename, version, len(contents), exptime, contents)
	resp, ok := reader.ReadBytes('\n')
	if ok != nil {
		fmt.Fprintf(os.Stderr, "Error in reading from socket in CasSuccess\n")
		fmt.Printf("Error in reading from socket in CasSuccess\n")
		debug.PrintStack()
		os.Exit(2)
	}
	arr := strings.Fields(string(resp))
	//expect(t, arr[0], "OK")
	if arr[0] != "OK" {
		fmt.Fprintf(os.Stderr, "Expected: %v found: %v in CasSuccess\n", "OK", arr[0])
		fmt.Printf("Expected: %v found: %v in CasSuccess\n", "OK", arr[0])
		debug.PrintStack()
		os.Exit(2)
	}
	version, err := strconv.ParseInt(arr[1], 10, 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Non-numeric version found")
		fmt.Printf("Non-numeric version found")
		debug.PrintStack()
		os.Exit(2)
	}
	return version
}
开发者ID:samkit993,项目名称:cs733,代码行数:27,代码来源:fsnode_test.go

示例6: testFindTestSummaryInOutput

func testFindTestSummaryInOutput(t *testing.T, isExpectToFind bool, fullOutput string, isRunSucess bool) {
	resStr := findTestSummaryInOutput(fullOutput, isRunSucess)
	if isExpectToFind && resStr == "" {
		t.Logf("Expected to find Test Summary in provided log.")
		debug.PrintStack()
		t.Fatalf("Provided output was: %s", fullOutput)
	}
	if !isExpectToFind && resStr != "" {
		t.Logf("Expected to NOT find Test Summary in provided log.")
		debug.PrintStack()
		t.Fatalf("Provided output was: %s", fullOutput)
	}
}
开发者ID:bazscsa,项目名称:steps-xcode-test,代码行数:13,代码来源:step_test.go

示例7: checkSortRes

func checkSortRes(t *testing.T, res [][]byte, values ...string) {
	if len(res) != len(values) {
		debug.PrintStack()
		t.Fatalf("invalid xsort res len, %d = %d", len(res), len(values))
	}

	for i := 0; i < len(res); i++ {
		if string(res[i]) != values[i] {
			debug.PrintStack()
			t.Fatalf("invalid xsort res at %d, %s != %s", i, res[i], values[i])
		}
	}
}
开发者ID:eswdd,项目名称:bosun,代码行数:13,代码来源:sort_test.go

示例8: RequestFlush

func (self *Serv) RequestFlush(client *Client, channel string, version int64) (err error) {
	defer func(client *Client) {
		r := recover()
		if r != nil {
			if self.logger != nil {
				self.logger.Error("server",
					"requestFlush failed",
					util.Fields{"error": r.(error).Error(),
						"uaid": client.UAID})
				debug.PrintStack()
			}
			if client != nil {
				self.ClientPing(client.Prop)
			}
		}
		return
	}(client)

	if client != nil {
		if self.logger != nil {
			self.logger.Info("server",
				"Requesting flush",
				util.Fields{"uaid": client.UAID,
					"channel": channel,
					"version": strconv.FormatInt(version, 10)})
		}

		// Attempt to send the command
		client.Worker.Flush(&client.PushWS, 0, channel, version)
	}
	return nil
}
开发者ID:rtilder,项目名称:pushgo,代码行数:32,代码来源:server.go

示例9: Errcheck

// Errcheck simplifies error handling by putting all the generic
// code in one place.
func Errcheck(err error) {
	if nil != err {
		debug.PrintStack()
		fmt.Printf("Error = %v\n", err)
		os.Exit(1)
	}
}
开发者ID:stmansour,项目名称:phonebook,代码行数:9,代码来源:stdlib.go

示例10: ConnectToMQTTServer

/*
Forward message to MQTT server
*/
func ConnectToMQTTServer(MQTTServerAddress string) (*client.Client, error) {
	defer func() {
		if err := recover(); err != nil {
			utils.Log.Println(err)
			debug.PrintStack()
		}
	}()

	cli := client.New(&client.Options{
		ErrorHandler: func(err error) {
			utils.Log.Println("MQTT Client error:", err)
		},
	})

	var err error

	RandomID := utils.MakeRandomID()

	err = cli.Connect(&client.ConnectOptions{
		Network:         "tcp",
		Address:         MQTTServerAddress,
		ClientID:        []byte(RandomID),
		CleanSession:    true,
		PINGRESPTimeout: 5 * time.Second,
		KeepAlive:       5,
	})

	if err != nil {
		return nil, err
	}

	return cli, nil
}
开发者ID:amghost,项目名称:message_service,代码行数:36,代码来源:mqtt.go

示例11: BuildErrorCatcher

/*
Middleware that catches panics, and:
	- logs them
	- optionally reports them to sentry - pass in "" if you don't want this
	- sends a 500 response
You can also use ThrowError() to raise an error that this middleware will catch, for example
if you want an error to be reported to sentry
*/
func BuildErrorCatcher(sentryClient *raven.Client) func(h http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		handler := func(w http.ResponseWriter, r *http.Request) {

			defer func() {
				err := recover()
				if err == nil {
					return
				}
				if sentryClient != nil {
					// Send the error to sentry
					const size = 1 << 12
					buf := make([]byte, size)
					n := runtime.Stack(buf, false)
					sentryClient.CaptureMessage(fmt.Sprintf("%v\nStacktrace:\n%s", err, buf[:n]), sentryClient.Tags)
				}

				switch err := err.(type) {
				case HttpError:
					log.Printf("Return response for error %s", err.Message)
					err.WriteResponse(w)
					return
				default:
					log.Printf("Panic: %v\n", err)
					debug.PrintStack()
					http.Error(w, http.StatusText(500), 500)
					return
				}
			}()

			h.ServeHTTP(w, r)
		}
		return http.HandlerFunc(handler)
	}
}
开发者ID:Zenithar,项目名称:golang-common,代码行数:43,代码来源:raven_errorcatcher.go

示例12: checkErr

func checkErr(err error) {
	if err != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
		debug.PrintStack()
		os.Exit(1)
	}
}
开发者ID:kirisky,项目名称:blog,代码行数:7,代码来源:upload.go

示例13: TestReadlocation1

func TestReadlocation1(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			debug.PrintStack()
			t.Errorf("Fatal Error:%s\n", err)
		}
	}()

	testfile := "testfile.txt"

	//create testfile
	content := `1	O1|O1(not set)|O1(not set)|0.0000|0.0000
2	Asia/Pacific Region|Asia/Pacific Region(not set)|Asia/Pacific Region(not set)|35.0000|105.0000
3	Europe|Europe(not set)|Europe(not set)|47.0000|8.0000
4	Andorra|Andorra(not set)|Andorra(not set)|42.5000|1.5000
5	United Arab Emirates|United Arab Emirates(not set)|United Arab Emirates(not set)|24.0000|54.0000
6	Afghanistan|Afghanistan(not set)|Afghanistan(not set)|33.0000|65.0000
7	Antigua and Barbuda|Antigua and Barbuda(not set)|Antigua and Barbuda(not set)|17.0500|-61.8000
`
	ostream, _ := os.Create(testfile)
	ostream.WriteString(content)
	ostream.Close()

	t.Log("Starting TestReadblock...")

	house, err := NewLocationpthouse(testfile)
	if err != nil {
		t.Errorf("Fatal Error:%s\n", err)
	}
	fmt.Printf("%+v", house)

	//delete testfile
	os.Remove(testfile)
}
开发者ID:asdfsx,项目名称:goprj,代码行数:34,代码来源:locationpt_test.go

示例14: TestDifference

func TestDifference(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			debug.PrintStack()
			t.Errorf("Fatal Error: %s\n", err)
		}
	}()
	t.Log("Starting TestDifference...")
	commonElem := genRandElement()
	set, _ := genRandSet(func() Set { return NewSimpleSet() })
	set.Add(commonElem)
	t.Logf("The set value: %v", set)
	set2, _ := genRandSet(func() Set { return NewSimpleSet() })
	set2.Add(commonElem)
	t.Logf("The set value (2): %v", set2)
	dSet := Difference(set, set2)
	for _, v := range dSet.Elements() {
		if !set.Contains(v) {
			t.Errorf("ERROR: The set value %v do not contains %v!",
				set, v)
			t.FailNow()
		}
		if set2.Contains(v) {
			t.Errorf("ERROR: The set value %v contains %v!",
				set2, v)
			t.FailNow()
		}
	}
	t.Logf("The set value %v is a differenced set of %v to %v", dSet, set, set2)
}
开发者ID:asdfsx,项目名称:goprj,代码行数:30,代码来源:set_test.go

示例15: TestUnion

func TestUnion(t *testing.T) {
	defer func() {
		if err := recover(); err != nil {
			debug.PrintStack()
			t.Errorf("Fatal Error: %s\n", err)
		}
	}()
	t.Log("Starting TestUnion...")
	set, _ := genRandSet(func() Set { return NewSimpleSet() })
	t.Logf("The set value: %v", set)
	set2, _ := genRandSet(func() Set { return NewSimpleSet() })
	uSet := Union(set, set2)
	t.Logf("The set value (2): %v", set2)
	for _, v := range set.Elements() {
		if !uSet.Contains(v) {
			t.Errorf("ERROR: The union set value %v do not contains %v!",
				uSet, v)
			t.FailNow()
		}
	}
	for _, v := range set2.Elements() {
		if !uSet.Contains(v) {
			t.Errorf("ERROR: The union set value %v do not contains %v!",
				uSet, v)
			t.FailNow()
		}
	}
	t.Logf("The set value %v is a unioned set of %v and %v", uSet, set, set2)
}
开发者ID:asdfsx,项目名称:goprj,代码行数:29,代码来源:set_test.go


注:本文中的runtime/debug.PrintStack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。