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
0fcbf33e
Commit
0fcbf33e
authored
Jun 29, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
936e6550
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
4 deletions
+77
-4
error.go
error.go
+69
-2
git-backup.go
git-backup.go
+8
-2
No files found.
error.go
View file @
0fcbf33e
...
...
@@ -37,6 +37,11 @@ func (e *Error) Error() string {
// raise error to upper level
func
raise
(
arg
interface
{})
{
// XXX is it ok?
e
,
ok
:=
arg
.
(
*
Error
)
if
ok
{
panic
(
e
)
// reraise
}
panic
(
&
Error
{
arg
,
nil
})
}
...
...
@@ -118,6 +123,65 @@ func erraddcontext(f func() interface{}) {
}
// get name of currently running function (caller of myfuncname())
func
myfuncname
()
string
{
pcv
:=
[
1
]
uintptr
{}
runtime
.
Callers
(
2
,
pcv
[
:
])
f
:=
runtime
.
FuncForPC
(
pcv
[
0
])
if
f
==
nil
{
return
""
}
return
f
.
Name
()
}
// add calling context to error
// n TODO
func
erraddcallercontext
(
topfunc
string
,
e
*
Error
)
*
Error
{
// all callers
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
1
,
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 topfunc
if
topfunc
!=
""
&&
frame
.
Function
==
topfunc
{
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
:
]
for
_
,
f
:=
range
funcv
{
f
=
strings
.
TrimPrefix
(
f
,
"main."
)
e
=
&
Error
{
f
,
e
}
}
return
e
}
// build error message associated with e
// should be called from under errcatch - in place which caught the error
func
errmessage
(
e
*
Error
)
string
{
...
...
@@ -125,7 +189,8 @@ func errmessage(e *Error) string {
var
pcv
=
[]
uintptr
{
0
}
for
{
pcv
=
make
([]
uintptr
,
2
*
len
(
pcv
))
n
:=
runtime
.
Callers
(
0
,
pcv
)
//n := runtime.Callers(0, pcv)
n
:=
runtime
.
Callers
(
1
,
pcv
)
if
n
<
len
(
pcv
)
{
pcv
=
pcv
[
:
n
]
break
...
...
@@ -138,8 +203,10 @@ func errmessage(e *Error) string {
for
more
:=
true
;
more
;
{
var
frame
runtime
.
Frame
frame
,
more
=
frames
.
Next
()
// do not go beyond main
//
// do not go beyond main
if
frame
.
Function
==
"main.main"
{
// do not go beyond caller
// if len(funcv) > 0 && frame.Function == funcv[0] {
break
}
// skip intermediates
...
...
git-backup.go
View file @
0fcbf33e
...
...
@@ -421,6 +421,8 @@ func cmd_pull_(pullspecv []PullSpec) {
// prefix namespace and this way won't leave stale removed things)
xgit
(
"rm"
,
"--cached"
,
"-r"
,
"--ignore-unmatch"
,
"--"
,
prefix
)
curfunc
:=
myfuncname
()
fmt
.
Printf
(
"curfunc: %q
\n
"
,
curfunc
)
err
:=
filepath
.
Walk
(
dir
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
(
errout
error
)
{
// any error -> stop
if
err
!=
nil
{
...
...
@@ -430,7 +432,9 @@ func cmd_pull_(pullspecv []PullSpec) {
// propagate exceptions properly via filepath.Walk as errors (filepath is not our code)
defer
errcatch
(
func
(
e
*
Error
)
{
errout
=
e
//errout = e
//errout = &Error{errmessage(e), nil}
errout
=
erraddcallercontext
(
curfunc
,
e
)
})
// files -> add directly to index to commit later
...
...
@@ -475,7 +479,9 @@ func cmd_pull_(pullspecv []PullSpec) {
if
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
Error
);
ok
{
// this was already raised - reraise
panic
(
err
)
//panic(err)
//raise(err.(*Error).arg)
raise
(
err
)
}
raisef
(
"pulling from %s: %s"
,
dir
,
err
)
...
...
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