-
-
Notifications
You must be signed in to change notification settings - Fork 431
Use the CLI's error codes to detect when the primary package index, library index, hardware platform is missing on IDE2 startup #1925
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
Comments
IDE2 cannot yet adapt the changes: arduino/arduino-cli#2076 On IDE2's side, we have to figure out how to convert such messages to objects in a generic way assuming the client does not know what the type is: [
{
"code": 9,
"message": "Error loading hardware platform: discovery builtin:serial-discovery not found",
"detailsList": [
{
"typeUrl": "type.googleapis.com/cc.arduino.cli.commands.v1.PlatformLoadingError",
"value": ""
}
]
},
{
"code": 9,
"message": "Loading index file: loading json index file /Users/a.kitta/Library/Arduino15/package_index.json: open /Users/a.kitta/Library/Arduino15/package_index.json: no such file or directory",
"detailsList": [
{
"typeUrl": "type.googleapis.com/cc.arduino.cli.commands.v1.FailedInstanceInitError",
"value": "CAIStAFMb2FkaW5nIGluZGV4IGZpbGU6IGxvYWRpbmcganNvbiBpbmRleCBmaWxlIC9Vc2Vycy9hLmtpdHRhL0xpYnJhcnkvQXJkdWlubzE1L3BhY2thZ2VfaW5kZXguanNvbjogb3BlbiAvVXNlcnMvYS5raXR0YS9MaWJyYXJ5L0FyZHVpbm8xNS9wYWNrYWdlX2luZGV4Lmpzb246IG5vIHN1Y2ggZmlsZSBvciBkaXJlY3Rvcnk="
}
]
}
] Something like this works, but the error types are unknown upfront let unpacked: unknown = undefined;
const typeName = any.getTypeName();
switch (typeName) {
case 'cc.arduino.cli.commands.v1.FailedInstanceInitError': {
unpacked = any.unpack(
FailedInstanceInitError.deserializeBinary,
typeName
);
break;
}
case 'cc.arduino.cli.commands.v1.PlatformLoadingError': {
unpacked = any.unpack(
PlatformLoadingError.deserializeBinary,
typeName
);
break;
}
} |
In golang, we call the Here the go snippet: // res is the response from the Init call
if status := res.GetError(); status != nil {
// GetCode() returns the gRPC error code, it's usually useless
fmt.Println()
fmt.Printf("Init error code: %v\n", status.GetCode())
// from the status we get the details
details := status.GetDetails()
if len(details) > 0 {
// if there are details let's examine the first one, and call UnmarshalNew on that one
detail, unmarshalError := status.GetDetails()[0].UnmarshalNew()
// detail is a "protoreflect.ProtoMessage" (basically a super interface of all protobuf objects)
fmt.Printf(" detail type: %T\n", detail) // this prints the actual type of details
// with the following type-switch we typecast it to a concrete type
switch err := detail.(type) {
case *rpc.FailedInstanceInitError:
fmt.Println(" reason:", err.GetReason()) // GetReason returns a grpc enum FailedInstanceInitReason
fmt.Println(" msg:", err.GetMessage())
case *rpc.PlatformLoadingError:
fmt.Println(" no more details")
}
}
} this outputs:
I'm not familiar with the JS binding, Is there a similar method in JS? |
Thanks for the snippet. I have not yet found the JS equivalent of: // with the following type-switch we typecast it to a concrete type
switch err := detail.(type) {
case *rpc.FailedInstanceInitError:
fmt.Println(" reason:", err.GetReason()) // GetReason returns a grpc enum FailedInstanceInitReason
fmt.Println(" msg:", err.GetMessage())
case *rpc.PlatformLoadingError:
fmt.Println(" no more details")
} At least, JS can switch on the |
Ref: #1925 Signed-off-by: Akos Kitta <[email protected]>
Ref: #1925 Signed-off-by: Akos Kitta <[email protected]>
Describe the request
The CLI can programmatically indicate when the
InitRequest
has failed: arduino/arduino-cli#2076IDE2 should eliminate the error-prone message parsing and use error codes to be more robust.
Describe the current behavior
IDE2 parsers the English error message and try to detect the error. This can be problematic when the user's default CLI language is other than English.
Arduino IDE version
2.0.4
Operating system
macOS
Operating system version
12.6.3
Additional context
No response
Issue checklist
The text was updated successfully, but these errors were encountered: