Skip to content

Commit

Permalink
Merge pull request #17 from ellizio/exception-handling
Browse files Browse the repository at this point in the history
Exception handling
  • Loading branch information
ellizio authored Apr 8, 2024
2 parents b65ea29 + 14ba8e4 commit 46d5094
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
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)
}

0 comments on commit 46d5094

Please sign in to comment.