Skip to content

Commit

Permalink
Merge pull request #991 from katiewasnothere/remove_extra_info
Browse files Browse the repository at this point in the history
Remove extra info from error logs
  • Loading branch information
katiewasnothere authored Apr 7, 2021
2 parents 7fa8bda + f731440 commit e811ee7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 47 deletions.
8 changes: 1 addition & 7 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type NetworkNotFoundError = hns.NetworkNotFoundError
type ProcessError struct {
Process *process
Operation string
ExtraInfo string
Err error
Events []hcs.ErrorEvent
}
Expand All @@ -92,7 +91,6 @@ type ProcessError struct {
type ContainerError struct {
Container *container
Operation string
ExtraInfo string
Err error
Events []hcs.ErrorEvent
}
Expand Down Expand Up @@ -125,10 +123,6 @@ func (e *ContainerError) Error() string {
s += "\n" + ev.String()
}

if e.ExtraInfo != "" {
s += " extra info: " + e.ExtraInfo
}

return s
}

Expand Down Expand Up @@ -238,7 +232,7 @@ func getInnerError(err error) error {

func convertSystemError(err error, c *container) error {
if serr, ok := err.(*hcs.SystemError); ok {
return &ContainerError{Container: c, Operation: serr.Op, ExtraInfo: serr.Extra, Err: serr.Err, Events: serr.Events}
return &ContainerError{Container: c, Operation: serr.Op, Err: serr.Err, Events: serr.Events}
}
return err
}
Expand Down
7 changes: 1 addition & 6 deletions internal/hcs/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ type SystemError struct {
ID string
Op string
Err error
Extra string
Events []ErrorEvent
}

Expand All @@ -182,9 +181,6 @@ func (e *SystemError) Error() string {
for _, ev := range e.Events {
s += "\n" + ev.String()
}
if e.Extra != "" {
s += "\n(extra info: " + e.Extra + ")"
}
return s
}

Expand All @@ -198,15 +194,14 @@ func (e *SystemError) Timeout() bool {
return ok && err.Timeout()
}

func makeSystemError(system *System, op string, extra string, err error, events []ErrorEvent) error {
func makeSystemError(system *System, op string, err error, events []ErrorEvent) error {
// Don't double wrap errors
if _, ok := err.(*SystemError); ok {
return err
}
return &SystemError{
ID: system.ID(),
Op: op,
Extra: extra,
Err: err,
Events: events,
}
Expand Down
68 changes: 34 additions & 34 deletions internal/hcs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
_ = computeSystem.Terminate(ctx)
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}
}

Expand All @@ -85,7 +85,7 @@ func CreateComputeSystem(ctx context.Context, id string, hcsDocumentInterface in
// ignore a failure here.
_ = computeSystem.Terminate(ctx)
}
return nil, makeSystemError(computeSystem, operation, hcsDocument, err, events)
return nil, makeSystemError(computeSystem, operation, err, events)
}
go computeSystem.waitBackground()
if err = computeSystem.getCachedProperties(ctx); err != nil {
Expand All @@ -102,7 +102,7 @@ func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
handle, resultJSON, err := vmcompute.HcsOpenComputeSystem(ctx, id)
events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
return nil, makeSystemError(computeSystem, operation, err, events)
}
computeSystem.handle = handle
defer func() {
Expand All @@ -111,7 +111,7 @@ func OpenComputeSystem(ctx context.Context, id string) (*System, error) {
}
}()
if err = computeSystem.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}
go computeSystem.waitBackground()
if err = computeSystem.getCachedProperties(ctx); err != nil {
Expand Down Expand Up @@ -187,13 +187,13 @@ func (computeSystem *System) Start(ctx context.Context) (err error) {
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

resultJSON, err := vmcompute.HcsStartComputeSystem(ctx, computeSystem.handle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}

return nil
Expand All @@ -220,7 +220,7 @@ func (computeSystem *System) Shutdown(ctx context.Context) error {
switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}
return nil
}
Expand All @@ -241,7 +241,7 @@ func (computeSystem *System) Terminate(ctx context.Context) error {
switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}
return nil
}
Expand All @@ -263,10 +263,10 @@ func (computeSystem *System) waitBackground() {
log.G(ctx).Debug("system exited")
case ErrVmcomputeUnexpectedExit:
log.G(ctx).Debug("unexpected system exit")
computeSystem.exitError = makeSystemError(computeSystem, operation, "", err, nil)
computeSystem.exitError = makeSystemError(computeSystem, operation, err, nil)
err = nil
default:
err = makeSystemError(computeSystem, operation, "", err, nil)
err = makeSystemError(computeSystem, operation, err, nil)
}
computeSystem.closedWaitOnce.Do(func() {
computeSystem.waitError = err
Expand Down Expand Up @@ -304,21 +304,21 @@ func (computeSystem *System) Properties(ctx context.Context, types ...schema1.Pr

queryBytes, err := json.Marshal(schema1.PropertyQuery{PropertyTypes: types})
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}

propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
return nil, makeSystemError(computeSystem, operation, err, events)
}

if propertiesJSON == "" {
return nil, ErrUnexpectedValue
}
properties := &schema1.ContainerProperties{}
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}

return properties, nil
Expand All @@ -333,21 +333,21 @@ func (computeSystem *System) PropertiesV2(ctx context.Context, types ...hcsschem

queryBytes, err := json.Marshal(hcsschema.PropertyQuery{PropertyTypes: types})
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}

propertiesJSON, resultJSON, err := vmcompute.HcsGetComputeSystemProperties(ctx, computeSystem.handle, string(queryBytes))
events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
return nil, makeSystemError(computeSystem, operation, err, events)
}

if propertiesJSON == "" {
return nil, ErrUnexpectedValue
}
properties := &hcsschema.Properties{}
if err := json.Unmarshal([]byte(propertiesJSON), properties); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}

return properties, nil
Expand All @@ -368,13 +368,13 @@ func (computeSystem *System) Pause(ctx context.Context) (err error) {
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

resultJSON, err := vmcompute.HcsPauseComputeSystem(ctx, computeSystem.handle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}

return nil
Expand All @@ -395,13 +395,13 @@ func (computeSystem *System) Resume(ctx context.Context) (err error) {
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

resultJSON, err := vmcompute.HcsResumeComputeSystem(ctx, computeSystem.handle, "")
events, err := processAsyncHcsResult(ctx, err, resultJSON, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}

return nil
Expand All @@ -427,13 +427,13 @@ func (computeSystem *System) Save(ctx context.Context, options interface{}) (err
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

result, err := vmcompute.HcsSaveComputeSystem(ctx, computeSystem.handle, string(saveOptions))
events, err := processAsyncHcsResult(ctx, err, result, computeSystem.callbackNumber, hcsNotificationSystemSaveCompleted, &timeout.SystemSave)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, events)
return makeSystemError(computeSystem, operation, err, events)
}

return nil
Expand All @@ -444,19 +444,19 @@ func (computeSystem *System) createProcess(ctx context.Context, operation string
defer computeSystem.handleLock.RUnlock()

if computeSystem.handle == 0 {
return nil, nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return nil, nil, makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

configurationb, err := json.Marshal(c)
if err != nil {
return nil, nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, nil, makeSystemError(computeSystem, operation, err, nil)
}

configuration := string(configurationb)
processInfo, processHandle, resultJSON, err := vmcompute.HcsCreateProcess(ctx, computeSystem.handle, configuration)
events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, nil, makeSystemError(computeSystem, operation, configuration, err, events)
return nil, nil, makeSystemError(computeSystem, operation, err, events)
}

log.G(ctx).WithField("pid", processInfo.ProcessId).Debug("created process pid")
Expand All @@ -478,15 +478,15 @@ func (computeSystem *System) CreateProcess(ctx context.Context, c interface{}) (

pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}
process.stdin = pipes[0]
process.stdout = pipes[1]
process.stderr = pipes[2]
process.hasCachedStdio = true

if err = process.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}
go process.waitBackground()

Expand All @@ -501,18 +501,18 @@ func (computeSystem *System) OpenProcess(ctx context.Context, pid int) (*Process
operation := "hcsshim::System::OpenProcess"

if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return nil, makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

processHandle, resultJSON, err := vmcompute.HcsOpenProcess(ctx, computeSystem.handle, uint32(pid))
events := processHcsResult(ctx, resultJSON)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
return nil, makeSystemError(computeSystem, operation, err, events)
}

process := newProcess(processHandle, pid, computeSystem)
if err = process.registerCallback(ctx); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
return nil, makeSystemError(computeSystem, operation, err, nil)
}
go process.waitBackground()

Expand All @@ -536,12 +536,12 @@ func (computeSystem *System) Close() (err error) {
}

if err = computeSystem.unregisterCallback(ctx); err != nil {
return makeSystemError(computeSystem, operation, "", err, nil)
return makeSystemError(computeSystem, operation, err, nil)
}

err = vmcompute.HcsCloseComputeSystem(ctx, computeSystem.handle)
if err != nil {
return makeSystemError(computeSystem, operation, "", err, nil)
return makeSystemError(computeSystem, operation, err, nil)
}

computeSystem.handle = 0
Expand Down Expand Up @@ -618,7 +618,7 @@ func (computeSystem *System) Modify(ctx context.Context, config interface{}) err
operation := "hcsshim::System::Modify"

if computeSystem.handle == 0 {
return makeSystemError(computeSystem, operation, "", ErrAlreadyClosed, nil)
return makeSystemError(computeSystem, operation, ErrAlreadyClosed, nil)
}

requestBytes, err := json.Marshal(config)
Expand All @@ -630,7 +630,7 @@ func (computeSystem *System) Modify(ctx context.Context, config interface{}) err
resultJSON, err := vmcompute.HcsModifyComputeSystem(ctx, computeSystem.handle, requestJSON)
events := processHcsResult(ctx, resultJSON)
if err != nil {
return makeSystemError(computeSystem, operation, requestJSON, err, events)
return makeSystemError(computeSystem, operation, err, events)
}

return nil
Expand Down

0 comments on commit e811ee7

Please sign in to comment.