Repository navigation
chore: Move shared CLI error handling into common errors #1483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package clicore | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| clierrors "github.com/hatayama/unity-cli-loop/common/errors" | ||
| "github.com/hatayama/unity-cli-loop/common/unityipc" | ||
| ) | ||
|
|
||
| const ( | ||
| ErrorCodeInvalidArgument = clierrors.ErrorCodeInvalidArgument | ||
| ErrorCodeUnityNotReachable = clierrors.ErrorCodeUnityNotReachable | ||
| ErrorCodeUnityStartupTimeout = clierrors.ErrorCodeUnityStartupTimeout | ||
| ErrorCodeUnityProcessExitTimeout = clierrors.ErrorCodeUnityProcessExitTimeout | ||
| ErrorCodeCLIUpdateRequired = clierrors.ErrorCodeCLIUpdateRequired | ||
| ErrorCodeToolDisabled = clierrors.ErrorCodeToolDisabled | ||
| ErrorCodeCompileWaitTimeout = clierrors.ErrorCodeCompileWaitTimeout | ||
| ErrorCodeControlPlayModeWaitTimeout = clierrors.ErrorCodeControlPlayModeWaitTimeout | ||
| ErrorCodeControlPlayModeCompileErrors = clierrors.ErrorCodeControlPlayModeCompileErrors | ||
| ErrorCodePausePointNotEnabled = clierrors.ErrorCodePausePointNotEnabled | ||
| ErrorCodePausePointWaitTimeout = clierrors.ErrorCodePausePointWaitTimeout | ||
| ErrorCodePausePointExpired = clierrors.ErrorCodePausePointExpired | ||
| ErrorCodePausePointCleared = clierrors.ErrorCodePausePointCleared | ||
| ErrorCodeInternalError = clierrors.ErrorCodeInternalError | ||
|
|
||
| ErrorPhaseArgumentParsing = clierrors.ErrorPhaseArgumentParsing | ||
| ErrorPhaseProjectResolve = clierrors.ErrorPhaseProjectResolve | ||
| ErrorPhaseDispatch = clierrors.ErrorPhaseDispatch | ||
| ErrorPhaseConnection = clierrors.ErrorPhaseConnection | ||
| ErrorPhaseResponseWaiting = clierrors.ErrorPhaseResponseWaiting | ||
| ErrorPhaseCompileWaiting = clierrors.ErrorPhaseCompileWaiting | ||
| ErrorPhaseExecution = clierrors.ErrorPhaseExecution | ||
| ) | ||
|
|
||
| type ( | ||
| CLIError = clierrors.CLIError | ||
| CLIErrorEnvelope = clierrors.CLIErrorEnvelope | ||
| ErrorContext = clierrors.ErrorContext | ||
| ArgumentError = clierrors.ArgumentError | ||
| UnityServerNotRespondingError = clierrors.UnityServerNotRespondingError | ||
| ) | ||
|
|
||
| func WriteErrorEnvelope(writer io.Writer, err CLIError) { | ||
| clierrors.WriteErrorEnvelope(writer, err) | ||
| } | ||
|
|
||
| func WriteClassifiedError(writer io.Writer, err error, context ErrorContext) { | ||
| clierrors.WriteClassifiedError(writer, err, context) | ||
| } | ||
|
|
||
| func WriteToolFailure(writer io.Writer, err error, outcome unityipc.UnitySendOutcome, context ErrorContext) { | ||
| clierrors.WriteToolFailure(writer, err, outcome, context) | ||
| } | ||
|
|
||
| func ClassifyError(err error, context ErrorContext) CLIError { | ||
| return clierrors.ClassifyError(err, context) | ||
| } | ||
|
|
||
| func MissingValueArgumentError(option string) *ArgumentError { | ||
| return clierrors.MissingValueArgumentError(option) | ||
| } | ||
|
|
||
| func InvalidValueArgumentError(option string, received string, expectedType string) *ArgumentError { | ||
| return clierrors.InvalidValueArgumentError(option, received, expectedType) | ||
| } | ||
|
|
||
| func InternalCLIError(message string, context ErrorContext) CLIError { | ||
| return clierrors.InternalCLIError(message, context) | ||
| } | ||
|
|
||
| func IsTransportDisconnectError(err error) bool { | ||
| return clierrors.IsTransportDisconnectError(err) | ||
| } | ||
|
|
||
| func IsFinalResponseTimeoutError(err error) bool { | ||
| return clierrors.IsFinalResponseTimeoutError(err) | ||
| } | ||
|
|
||
| func RPCDataType(data map[string]any) string { | ||
| return clierrors.RPCDataType(data) | ||
| } | ||
|
|
||
| func UnknownCommandError(command string, cache ToolsCache, context ErrorContext) CLIError { | ||
| return clierrors.UnknownCommandError(command, availableCommandNames(cache), context) | ||
| } | ||
|
|
||
| func availableCommandNames(cache ToolsCache) []string { | ||
| seen := map[string]bool{} | ||
| names := []string{} | ||
| for _, name := range NativeCommandNamesForCompletion() { | ||
| seen[name] = true | ||
| names = append(names, name) | ||
| } | ||
| for _, tool := range cache.Tools { | ||
| if seen[tool.Name] { | ||
| continue | ||
| } | ||
| seen[tool.Name] = true | ||
| names = append(names, tool.Name) | ||
| } | ||
| return names | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package clicore | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestAvailableCommandNamesIncludesBuiltIns(t *testing.T) { | ||
| // Verifies the clicore compatibility wrapper still contributes built-in commands. | ||
| names := availableCommandNames(ToolsCache{}) | ||
| expectedBuiltIns := []string{"launch", "list", "sync", "focus-window", "wait-for-pause-point", "pause-point-status", "skills", "completion", "install", "update", "uninstall"} | ||
| for index, expected := range expectedBuiltIns { | ||
| if names[index] != expected { | ||
| t.Fatalf("built-in command mismatch: %#v", names) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...mmon/clicore/error_editor_unresponsive.go → ...ommon/errors/error_editor_unresponsive.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package clicore | ||
| package clierrors | ||
|
|
||
| import "github.com/hatayama/unity-cli-loop/common/unityipc" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package clierrors | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| // UnityServerNotRespondingError reports that a running Unity Editor accepted a | ||
| // connection but its Unity CLI Loop server did not respond in time. Both the | ||
| // dispatcher's launch-readiness wait and the runner's connection retry loop | ||
| // construct this error, and the shared CORE classifiers turn it into a CLIError. | ||
| type UnityServerNotRespondingError struct { | ||
| ProjectRoot string | ||
| Endpoint string | ||
| Cause error | ||
| } | ||
|
|
||
| func (err UnityServerNotRespondingError) Error() string { | ||
| if err.Cause != nil { | ||
| return fmt.Sprintf("Unity is running but the Unity CLI Loop server is not responding: %s", err.Cause) | ||
| } | ||
| return "Unity is running but the Unity CLI Loop server is not responding" | ||
| } | ||
|
|
||
| func (err UnityServerNotRespondingError) Unwrap() error { | ||
| return err.Cause | ||
| } | ||
|
|
||
| func (err UnityServerNotRespondingError) causeText() string { | ||
| if err.Cause == nil { | ||
| return "" | ||
| } | ||
| return err.Cause.Error() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package clierrors | ||
|
|
||
| func firstNonEmpty(values ...string) string { | ||
| for _, value := range values { | ||
| if value != "" { | ||
| return value | ||
| } | ||
| } | ||
| return "" | ||
| } |
2 changes: 1 addition & 1 deletion
2
cli/common/clicore/transport_errors.go → cli/common/errors/transport_errors.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package clicore | ||
| package clierrors | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
cli/common/clicore/transport_errors_test.go → cli/common/errors/transport_errors_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package clicore | ||
| package clierrors | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "sharedInputsHash": "b58452f9c0f12c73da40ccdda7b87ee77e64b99a" | ||
| "sharedInputsHash": "4ffd3b6d8156471cab11096b0f52f3696937bdba" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "sharedInputsHash": "bdaecfb852b88de8634ae849eddd5e1b0c0f064e" | ||
| "sharedInputsHash": "552a3bbd8757b2357b7fca535453fdf2e416577c" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.