Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added VZErrorCode enum #99

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions errorcode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions vzerror.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package vz

// Error type returned by the Virtualization framework.
// The NSError domain is VZErrorDomain, the code is one of the ErrorCode constants.
//
//go:generate stringer -type=ErrorCode
type ErrorCode int

const (
// ErrorInternal is an internal error such as the virtual machine unexpectedly stopping.
ErrorInternal ErrorCode = 1 + iota

// ErrorInvalidVirtualMachineConfiguration represents invalid machine configuration.
ErrorInvalidVirtualMachineConfiguration

// ErrorInvalidVirtualMachineState represents API used with a machine in the wrong state
// (e.g. interacting with a machine before it is running).
ErrorInvalidVirtualMachineState

// ErrorInvalidVirtualMachineStateTransition is invalid change of state
// (e.g. pausing a virtual machine that is not started).
ErrorInvalidVirtualMachineStateTransition

// ErrorInvalidDiskImage represents unrecognized disk image format or invalid disk image.
ErrorInvalidDiskImage

// ErrorVirtualMachineLimitExceeded represents the running virtual machine limit was exceeded.
// Available from macOS 12.0 and above.
ErrorVirtualMachineLimitExceeded

// ErrorNetworkError represents network error occurred.
// Available from macOS 13.0 and above.
ErrorNetworkError

// ErrorOutOfDiskSpace represents machine ran out of disk space.
// Available from macOS 13.0 and above.
ErrorOutOfDiskSpace

// ErrorOperationCancelled represents the operation was cancelled.
// Available from macOS 13.0 and above.
ErrorOperationCancelled

// ErrorNotSupported represents the operation is not supported.
// Available from macOS 13.0 and above.
ErrorNotSupported
)

/* macOS installation errors. */
const (
// ErrorRestoreImageCatalogLoadFailed represents the restore image catalog failed to load.
// Available from macOS 13.0 and above.
ErrorRestoreImageCatalogLoadFailed ErrorCode = 10001 + iota

// ErrorInvalidRestoreImageCatalog represents the restore image catalog is invalid.
// Available from macOS 13.0 and above.
ErrorInvalidRestoreImageCatalog

// ErrorNoSupportedRestoreImagesInCatalog represents the restore image catalog has no supported restore images.
// Available from macOS 13.0 and above.
ErrorNoSupportedRestoreImagesInCatalog

// ErrorRestoreImageLoadFailed represents the restore image failed to load.
// Available from macOS 13.0 and above.
ErrorRestoreImageLoadFailed

// ErrorInvalidRestoreImage represents the restore image is invalid.
// Available from macOS 13.0 and above.
ErrorInvalidRestoreImage

// ErrorInstallationRequiresUpdate represents a software update is required to complete the installation.
// Available from macOS 13.0 and above.
ErrorInstallationRequiresUpdate

// ErrorInstallationFailed is an error occurred during installation.
// Available from macOS 13.0 and above.
ErrorInstallationFailed
)
106 changes: 106 additions & 0 deletions vzerror_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package vz_test

import (
"testing"

"github.com/Code-Hex/vz/v2"
)

func TestErrorCodeString(t *testing.T) {
t.Run("fundamental error code", func(t *testing.T) {
cases := []struct {
code vz.ErrorCode
want string
}{
{
code: vz.ErrorInternal,
want: "ErrorInternal",
},
{
code: vz.ErrorInvalidVirtualMachineConfiguration,
want: "ErrorInvalidVirtualMachineConfiguration",
},
{
code: vz.ErrorInvalidVirtualMachineState,
want: "ErrorInvalidVirtualMachineState",
},
{
code: vz.ErrorInvalidVirtualMachineStateTransition,
want: "ErrorInvalidVirtualMachineStateTransition",
},
{
code: vz.ErrorInvalidDiskImage,
want: "ErrorInvalidDiskImage",
},
{
code: vz.ErrorVirtualMachineLimitExceeded,
want: "ErrorVirtualMachineLimitExceeded",
},
{
code: vz.ErrorNetworkError,
want: "ErrorNetworkError",
},

{
code: vz.ErrorOutOfDiskSpace,
want: "ErrorOutOfDiskSpace",
},
{
code: vz.ErrorOperationCancelled,
want: "ErrorOperationCancelled",
},
{
code: vz.ErrorNotSupported,
want: "ErrorNotSupported",
},
}
for _, tc := range cases {
got := tc.code.String()
if tc.want != got {
t.Fatalf("want %q but got %q", tc.want, got)
}
}
})

t.Run("macOS installation", func(t *testing.T) {
cases := []struct {
code vz.ErrorCode
want string
}{
{
code: vz.ErrorRestoreImageCatalogLoadFailed,
want: "ErrorRestoreImageCatalogLoadFailed",
},
{
code: vz.ErrorInvalidRestoreImageCatalog,
want: "ErrorInvalidRestoreImageCatalog",
},
{
code: vz.ErrorNoSupportedRestoreImagesInCatalog,
want: "ErrorNoSupportedRestoreImagesInCatalog",
},
{
code: vz.ErrorRestoreImageLoadFailed,
want: "ErrorRestoreImageLoadFailed",
},
{
code: vz.ErrorInvalidRestoreImage,
want: "ErrorInvalidRestoreImage",
},
{
code: vz.ErrorInstallationRequiresUpdate,
want: "ErrorInstallationRequiresUpdate",
},
{
code: vz.ErrorInstallationFailed,
want: "ErrorInstallationFailed",
},
}
for _, tc := range cases {
got := tc.code.String()
if tc.want != got {
t.Fatalf("want %q but got %q", tc.want, got)
}
}
})
}