Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
git-backup
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
git-backup
Commits
936e6550
Commit
936e6550
authored
Jun 29, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5f319762
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
51 deletions
+60
-51
error.go
error.go
+59
-0
git-backup.go
git-backup.go
+1
-51
No files found.
error.go
View file @
936e6550
...
...
@@ -15,6 +15,7 @@ package main
import
(
"fmt"
"runtime"
"strings"
)
...
...
@@ -115,3 +116,61 @@ func erraddcontext(f func() interface{}) {
arg
:=
f
()
panic
(
&
Error
{
arg
,
e
})
}
// build error message associated with e
// should be called from under errcatch - in place which caught the error
func
errmessage
(
e
*
Error
)
string
{
// all callers
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
0
,
pcv
)
if
n
<
len
(
pcv
)
{
pcv
=
pcv
[
:
n
]
break
}
}
// pcv -> function names
funcv
:=
[]
string
{}
frames
:=
runtime
.
CallersFrames
(
pcv
)
for
more
:=
true
;
more
;
{
var
frame
runtime
.
Frame
frame
,
more
=
frames
.
Next
()
// do not go beyond main
if
frame
.
Function
==
"main.main"
{
break
}
// skip intermediates
if
strings
.
HasSuffix
(
frame
.
Function
,
"_"
)
{
continue
}
funcv
=
append
(
funcv
,
frame
.
Function
)
}
// do not show anything after raise*()
iraise
:=
-
1
for
i
,
funcname
:=
range
(
funcv
)
{
if
strings
.
HasPrefix
(
funcname
,
"main.raise"
)
{
iraise
=
i
}
}
funcv
=
funcv
[
iraise
+
1
:
]
// print funcv prefix in top-down order
msgprefix
:=
[]
string
{}
for
i
:=
range
(
funcv
)
{
f
:=
funcv
[
len
(
funcv
)
-
i
-
1
]
f
=
strings
.
TrimPrefix
(
f
,
"main."
)
msgprefix
=
append
(
msgprefix
,
f
)
}
msg
:=
strings
.
Join
(
append
(
msgprefix
,
""
),
": "
)
msg
+=
fmt
.
Sprint
(
e
)
if
!
strings
.
HasSuffix
(
msg
,
"
\n
"
)
{
msg
+=
"
\n
"
}
return
msg
}
git-backup.go
View file @
936e6550
...
...
@@ -66,7 +66,6 @@ import (
"os"
pathpkg
"path"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strings"
...
...
@@ -946,56 +945,7 @@ func main() {
// catch Error and report info from it
defer
errcatch
(
func
(
e
*
Error
)
{
// all callers
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
0
,
pcv
)
if
n
<
len
(
pcv
)
{
pcv
=
pcv
[
:
n
]
break
}
}
// pcv -> function names
funcv
:=
[]
string
{}
frames
:=
runtime
.
CallersFrames
(
pcv
)
for
more
:=
true
;
more
;
{
var
frame
runtime
.
Frame
frame
,
more
=
frames
.
Next
()
// do not go beyound main
if
frame
.
Function
==
"main.main"
{
break
}
// skip intermediates
if
strings
.
HasSuffix
(
frame
.
Function
,
"_"
)
{
continue
}
funcv
=
append
(
funcv
,
frame
.
Function
)
}
// do not show anything after raise*()
iraise
:=
-
1
for
i
,
funcname
:=
range
(
funcv
)
{
if
strings
.
HasPrefix
(
funcname
,
"main.raise"
)
{
iraise
=
i
}
}
funcv
=
funcv
[
iraise
+
1
:
]
// print funcv prefix in top-down order
msgprefix
:=
[]
string
{}
for
i
:=
range
(
funcv
)
{
f
:=
funcv
[
len
(
funcv
)
-
i
-
1
]
f
=
strings
.
TrimPrefix
(
f
,
"main."
)
msgprefix
=
append
(
msgprefix
,
f
)
}
msg
:=
strings
.
Join
(
append
(
msgprefix
,
""
),
": "
)
msg
+=
fmt
.
Sprint
(
e
)
if
!
strings
.
HasSuffix
(
msg
,
"
\n
"
)
{
msg
+=
"
\n
"
}
msg
:=
errmessage
(
e
)
fmt
.
Fprint
(
os
.
Stderr
,
msg
)
// also show traceback if debug
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment