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

Exception handling #17

Merged
merged 5 commits into from
Apr 8, 2024
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ Rider plugin to generate OData Reference using OData CLI

## ⚠️ Known Restrictions

TODO
1. Output metadata .xml file is always named `OData ServiceCsdl.xml` which will throw a runtime exception. See more [https://github.com/OData/ODataConnectedService/issues/384](https://github.com/OData/ODataConnectedService/issues/384)\
There is a workaround:\
`a.` Rename `OData ServiceCsdl.xml` to `<Service name>Csdl.xml`, where `<Service name>` is value from OData CLI UI dialog\
`b.` Adjust embedded resource path in `.csproj` file\
`c.` Find `GeneratedEdmModel.filePath` constant in `Reference.cs` and change value from `OData ServiceCsdl.xml` to `<Service name>Csdl.xml`, where `<Service name>` is value from OData CLI UI dialog

## Additional References

- [Changelog](https://github.com/ellizio/rider--plugin--odata-cli-ui/blob/master/CHANGELOG.md)
- [OData CLI](https://learn.microsoft.com/en-us/odata/odatacli/getting-started)
- [OData CLI](https://learn.microsoft.com/en-us/odata/odatacli/getting-started)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.jetbrains.rider.projectView.actions.isProjectModelReady
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.projectView.workspace.isProject
import com.jetbrains.rider.projectView.workspace.isWebReferenceFolder
import ru.ellizio.odatacliui.extensions.printCommandError
import ru.ellizio.odatacliui.models.ActionMetadata
import ru.ellizio.odatacliui.terminal.executors.CommandLineExecutor

Expand Down Expand Up @@ -61,10 +62,17 @@ class OpenCliDialogAction : AnAction() {
consoleView = CliToolWindowManager.getInstance(project).instantiateConsole()
}

val odataCliExecutor = CommandLineExecutor(project, model.buildODataCliCommand(), consoleView!!)
val success = odataCliExecutor.execute()
if (!success)
val odataCliCommand = model.buildODataCliCommand()
try {
val odataCliExecutor = CommandLineExecutor(project, odataCliCommand, consoleView!!)
val success = odataCliExecutor.execute()
if (!success)
return
}
catch (t: Throwable) {
consoleView!!.printCommandError(t, odataCliCommand.commandLineString)
return
}

project.lifetime.launchOnUi {
project.solution.protocolModel.addEmbeddedResource.startSuspending(project.lifetime, EmbeddedResourceDefinition(metadata.projectName, model.getCsdlPath()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.ellizio.odatacliui.extensions

import com.intellij.execution.ui.ConsoleView
import com.intellij.execution.ui.ConsoleViewContentType

fun ConsoleView.printCommandError(t: Throwable, command: String) {
print("Error attempting to call command ", ConsoleViewContentType.LOG_ERROR_OUTPUT)
print(command, ConsoleViewContentType.LOG_INFO_OUTPUT)
print(":${System.lineSeparator()}", ConsoleViewContentType.LOG_ERROR_OUTPUT)
print(t.localizedMessage, ConsoleViewContentType.ERROR_OUTPUT)
}
Loading