-
-
Notifications
You must be signed in to change notification settings - Fork 432
Better gRPC error handling #1251
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 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b7e8ff4
Proper gRPC error handling
cmaglie b6522c0
Update gRPC API of board command to return status.Status instead of e…
per1234 67c19f2
Update gRPC API of remaining commands to return status.Status instead…
per1234 17652b6
Replace custom error with protobuf message
per1234 c6b72b9
Handle details of any type in `core.PlatformUpgrade()` status
per1234 4696d07
Return nil on program action if an error occurred
cmaglie acf791e
Refactoring 'upload' commands
cmaglie 4fa1080
Refactoring 'board' commands
cmaglie ce3f802
Refactoring 'compile' commands
cmaglie 5890cb2
Refactoring 'core' commands
cmaglie 0195111
Refactoring 'debug' commands
cmaglie 1025981
Refactoring 'lib' commands
cmaglie 1e770ca
Refactoring 'sketch' commands
cmaglie 677fd55
Refactoring 'commands' commands
cmaglie 763fcb8
updated tests and fixed some error wording
cmaglie 50d17c4
fixed go lint warnings
cmaglie 89a61df
Apply suggestions from code review
cmaglie 4bcaf9c
Apply changes from code review
cmaglie 6bf77b9
fix i18n
cmaglie 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
Refactoring 'upload' commands
- Loading branch information
commit acf791ec27d908980e126e491b39a798054e4b82
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
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,207 @@ | ||
| // This file is part of arduino-cli. | ||
| // | ||
| // Copyright 2020 ARDUINO SA (http://www.arduino.cc/) | ||
| // | ||
| // This software is released under the GNU General Public License version 3, | ||
| // which covers the main part of arduino-cli. | ||
| // The terms of this license can be found at: | ||
| // https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| // | ||
| // You can be released from the requirements of the above licenses by purchasing | ||
| // a commercial license. Buying such a license is mandatory if you want to | ||
| // modify or otherwise use the software for commercial activities involving the | ||
| // Arduino software without disclosing the source code of your own applications. | ||
| // To purchase a commercial license, send an email to license@arduino.cc. | ||
|
|
||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| func composeErrorMsg(msg string, cause error) string { | ||
| if cause == nil { | ||
| return msg | ||
| } | ||
| return fmt.Sprintf("%v: %v", msg, cause) | ||
| } | ||
|
|
||
| // CommandError is an error that may be converted into a gRPC status. | ||
| type CommandError interface { | ||
| ToRPCStatus() *status.Status | ||
| } | ||
|
|
||
| // InvalidInstanceError is returned if the instance used in the command is not valid. | ||
| type InvalidInstanceError struct{} | ||
|
|
||
| func (e *InvalidInstanceError) Error() string { | ||
| return tr("Invalid instance") | ||
| } | ||
|
|
||
| func (e *InvalidInstanceError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.InvalidArgument, e.Error()) | ||
| } | ||
|
|
||
| // InvalidFQBNError is returned when the FQBN has syntax errors | ||
| type InvalidFQBNError struct { | ||
| Cause error | ||
| } | ||
|
|
||
| func (e *InvalidFQBNError) Error() string { | ||
| return composeErrorMsg(tr("Invalid FQBN"), e.Cause) | ||
| } | ||
|
|
||
| func (e *InvalidFQBNError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.InvalidArgument, e.Error()) | ||
| } | ||
|
|
||
| func (e *InvalidFQBNError) Unwrap() error { | ||
| return e.Cause | ||
| } | ||
|
|
||
| // MissingFQBNError is returned when the FQBN is mandatory and not specified | ||
| type MissingFQBNError struct{} | ||
|
|
||
| func (e *MissingFQBNError) Error() string { | ||
| return tr("Missing FQBN (Fully Qualified Board Name)") | ||
| } | ||
|
|
||
| func (e *MissingFQBNError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.InvalidArgument, e.Error()) | ||
| } | ||
|
|
||
| // UnknownFQBNError is returned when the FQBN is not found | ||
| type UnknownFQBNError struct { | ||
| Cause error | ||
| } | ||
|
|
||
| func (e *UnknownFQBNError) Error() string { | ||
| return composeErrorMsg(tr("Unknown FQBN"), e.Cause) | ||
| } | ||
|
|
||
| func (e *UnknownFQBNError) Unwrap() error { | ||
| return e.Cause | ||
| } | ||
|
|
||
| func (e *UnknownFQBNError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.NotFound, e.Error()) | ||
| } | ||
|
|
||
| // MissingPortProtocolError is returned when the port protocol is mandatory and not specified | ||
| type MissingPortProtocolError struct{} | ||
|
|
||
| func (e *MissingPortProtocolError) Error() string { | ||
| return tr("Missing port protocol") | ||
| } | ||
|
|
||
| func (e *MissingPortProtocolError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.InvalidArgument, e.Error()) | ||
| } | ||
|
|
||
| // MissingProgrammerError is returned when the programmer is mandatory and not specified | ||
| type MissingProgrammerError struct{} | ||
|
|
||
| func (e *MissingProgrammerError) Error() string { | ||
| return tr("Missing programmer") | ||
| } | ||
|
|
||
| func (e *MissingProgrammerError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.InvalidArgument, e.Error()) | ||
| } | ||
|
|
||
| // ProgreammerRequiredForUploadError is returned then the upload can be done only using a programmer | ||
| type ProgreammerRequiredForUploadError struct{} | ||
|
|
||
| func (e *ProgreammerRequiredForUploadError) Error() string { | ||
| return tr("A programmer is required to upload") | ||
| } | ||
|
|
||
| func (e *ProgreammerRequiredForUploadError) ToRPCStatus() *status.Status { | ||
| st, _ := status. | ||
| New(codes.InvalidArgument, e.Error()). | ||
| WithDetails(&rpc.ProgrammerIsRequiredForUploadError{}) | ||
| return st | ||
| } | ||
|
|
||
| // UnknownProgrammerError is returned when the programmer is not found | ||
| type UnknownProgrammerError struct { | ||
| Cause error | ||
| } | ||
|
|
||
| func (e *UnknownProgrammerError) Error() string { | ||
| return composeErrorMsg(tr("Unknown programmer"), e.Cause) | ||
| } | ||
|
|
||
| func (e *UnknownProgrammerError) Unwrap() error { | ||
| return e.Cause | ||
| } | ||
|
|
||
| func (e *UnknownProgrammerError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.NotFound, e.Error()) | ||
| } | ||
|
|
||
| // InvalidPlatformPropertyError is returned when a property in the platform is not valid | ||
| type InvalidPlatformPropertyError struct { | ||
| Property string | ||
| Value string | ||
| } | ||
|
|
||
| func (e *InvalidPlatformPropertyError) Error() string { | ||
| return tr("Invalid '%[1]s' property: %[2]s", e.Property, e.Value) | ||
| } | ||
|
|
||
| func (e *InvalidPlatformPropertyError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.FailedPrecondition, e.Error()) | ||
| } | ||
|
|
||
| // MissingPlatformPropertyError is returned when a property in the platform is not found | ||
| type MissingPlatformPropertyError struct { | ||
| Property string | ||
| } | ||
|
|
||
| func (e *MissingPlatformPropertyError) Error() string { | ||
| return tr("Property '%s' is undefined", e.Property) | ||
| } | ||
|
|
||
| func (e *MissingPlatformPropertyError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.FailedPrecondition, e.Error()) | ||
| } | ||
|
|
||
| // SketchNotFoundError is returned when the sketch is not found | ||
| type SketchNotFoundError struct { | ||
| Cause error | ||
| } | ||
|
|
||
| func (e *SketchNotFoundError) Error() string { | ||
| return composeErrorMsg(tr("Sketch not found"), e.Cause) | ||
| } | ||
|
|
||
| func (e *SketchNotFoundError) Unwrap() error { | ||
| return e.Cause | ||
| } | ||
|
|
||
| func (e *SketchNotFoundError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.NotFound, e.Error()) | ||
| } | ||
|
|
||
| // FailedUploadError is returned when the upload fails | ||
| type FailedUploadError struct { | ||
| Message string | ||
| Cause error | ||
| } | ||
|
|
||
| func (e *FailedUploadError) Error() string { | ||
| return composeErrorMsg(e.Message, e.Cause) | ||
| } | ||
|
|
||
| func (e *FailedUploadError) Unwrap() error { | ||
| return e.Cause | ||
| } | ||
|
|
||
| func (e *FailedUploadError) ToRPCStatus() *status.Status { | ||
| return status.New(codes.Internal, e.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
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.