extra panic protection in operations
This commit is contained in:
parent
46d584ec75
commit
ec3df496fe
@ -2,6 +2,7 @@ package operations
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -106,7 +107,13 @@ type detailsWriter interface {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Run begins a synchronous backup operation.
|
// Run begins a synchronous backup operation.
|
||||||
func (op *BackupOperation) Run(ctx context.Context) error {
|
func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err = clues.Wrap(r.(error), "panic recovery").WithClues(ctx).With("stacktrace", debug.Stack())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
ctx, end := D.Span(ctx, "operations:backup:run")
|
ctx, end := D.Span(ctx, "operations:backup:run")
|
||||||
defer func() {
|
defer func() {
|
||||||
end()
|
end()
|
||||||
@ -589,6 +596,11 @@ func (op *BackupOperation) persistResults(
|
|||||||
opStats.writeErr)
|
opStats.writeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opStats.gc == nil {
|
||||||
|
op.Status = Failed
|
||||||
|
return errors.New("data population never completed")
|
||||||
|
}
|
||||||
|
|
||||||
if opStats.readErr == nil && opStats.writeErr == nil && opStats.gc.Successful == 0 {
|
if opStats.readErr == nil && opStats.writeErr == nil && opStats.gc.Successful == 0 {
|
||||||
op.Status = NoData
|
op.Status = NoData
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package operations
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -106,6 +107,12 @@ type restorer interface {
|
|||||||
|
|
||||||
// Run begins a synchronous restore operation.
|
// Run begins a synchronous restore operation.
|
||||||
func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.Details, err error) {
|
func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.Details, err error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err = clues.Wrap(r.(error), "panic recovery").WithClues(ctx).With("stacktrace", debug.Stack())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
ctx, end := D.Span(ctx, "operations:restore:run")
|
ctx, end := D.Span(ctx, "operations:restore:run")
|
||||||
defer func() {
|
defer func() {
|
||||||
end()
|
end()
|
||||||
@ -250,6 +257,11 @@ func (op *RestoreOperation) persistResults(
|
|||||||
opStats.writeErr)
|
opStats.writeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opStats.gc == nil {
|
||||||
|
op.Status = Failed
|
||||||
|
return errors.New("data restoration never completed")
|
||||||
|
}
|
||||||
|
|
||||||
if opStats.readErr == nil && opStats.writeErr == nil && opStats.gc.Successful == 0 {
|
if opStats.readErr == nil && opStats.writeErr == nil && opStats.gc.Successful == 0 {
|
||||||
op.Status = NoData
|
op.Status = NoData
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,11 +87,12 @@ func (e *Errors) Fail(err error) *Errors {
|
|||||||
// setErr handles setting errors.err. Sync locking gets
|
// setErr handles setting errors.err. Sync locking gets
|
||||||
// handled upstream of this call.
|
// handled upstream of this call.
|
||||||
func (e *Errors) setErr(err error) *Errors {
|
func (e *Errors) setErr(err error) *Errors {
|
||||||
if e.err != nil {
|
if e.err == nil {
|
||||||
return e.addErr(err)
|
e.err = err
|
||||||
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
e.err = err
|
e.errs = append(e.errs, err)
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,6 +73,8 @@ func (suite *FaultErrorsUnitSuite) TestErr() {
|
|||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
n := fault.New(test.failFast)
|
n := fault.New(test.failFast)
|
||||||
require.NotNil(t, n)
|
require.NotNil(t, n)
|
||||||
|
require.NoError(t, n.Err())
|
||||||
|
require.Empty(t, n.Errs())
|
||||||
|
|
||||||
e := n.Fail(test.fail)
|
e := n.Fail(test.fail)
|
||||||
require.NotNil(t, e)
|
require.NotNil(t, e)
|
||||||
@ -90,6 +92,8 @@ func (suite *FaultErrorsUnitSuite) TestFail() {
|
|||||||
|
|
||||||
n := fault.New(false)
|
n := fault.New(false)
|
||||||
require.NotNil(t, n)
|
require.NotNil(t, n)
|
||||||
|
require.NoError(t, n.Err())
|
||||||
|
require.Empty(t, n.Errs())
|
||||||
|
|
||||||
n.Fail(assert.AnError)
|
n.Fail(assert.AnError)
|
||||||
assert.Error(t, n.Err())
|
assert.Error(t, n.Err())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user