Skip to content

Typed Errors  #19

Description

There was recently a commit, c898547, that added another return value to the create process func. It is used for type checking the type of error.

This pkg is pretty small right now so I think we can make this even better. There are many different ways for handling typed errors in Go. We can do something like the syscall package does with it's syscall.Errno which is a uintptr for these. Or we can define an error type in the package with codes so that we don't have to have multiple return results to find out a type safe way to get the error.

I suggest doing something like this but I wanted to get your input on what you think before I open a PR.

Option 1:

var (
WaitErrExecFailed=errors.New("hcsshim: wait exec failed")
// Known Win32 RC values which should be trappedWin32PipeHasBeenEnded=errors.New("hcsshim: The pipe has been ended")
Win32SystemShutdownIsInProgress=errors.New("hcsshim: A system shutdown is in progress")
Win32SpecifiedPathInvalid=errors.New("hcsshim: The specified path is invalid")
Win32SystemCannotFindThePathSpecified=errors.New("hcsshim: The system cannot find the path specified")
Win32InvalidArgument=errors.New("hcsshim: An invalid argument was supplied")
)

By doing this we have typed errors that are easily comparable by the consumer.

_, _, _, _, err:=CreateProcessInComputeSystem(id, true, ...)
iferr!=nil {
iferr==hcsshim.Win32InvalidArgument {
// do specific stuff
}
returnerr
}

Option two if you want to keep the codes from the types above then you can do something like the syscall pkg.

typeErrnouint32func (eErrno) Error() string { switche {
caseWin32InvalidArgument:
return"hcsshim: An invalid argument was supplied"
} }

What do you all think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions