Refactored code structure
This commit is contained in:
parent
9e52e2dd1c
commit
fd6e874b44
54 changed files with 583 additions and 450 deletions
30
src/build/errors/Stack.go
Normal file
30
src/build/errors/Stack.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package errors
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Stack generates a stack trace.
|
||||
func Stack() string {
|
||||
var (
|
||||
final []string
|
||||
buffer = make([]byte, 4096)
|
||||
n = runtime.Stack(buffer, false)
|
||||
stack = string(buffer[:n])
|
||||
lines = strings.Split(stack, "\n")
|
||||
)
|
||||
|
||||
for i := 6; i < len(lines); i += 2 {
|
||||
line := strings.TrimSpace(lines[i])
|
||||
space := strings.LastIndex(line, " ")
|
||||
|
||||
if space != -1 {
|
||||
line = line[:space]
|
||||
}
|
||||
|
||||
final = append(final, line)
|
||||
}
|
||||
|
||||
return strings.Join(final, "\n")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue