Skip to content

Commit 1b055d5

Browse files
committed
Throwing error when requested command does not exist
This would only happen on a programming error - in which case we almost certainly want an error because the caller is expecting a command to be executed and that's not being done. Ran into this when I was testing out a PR but I had not yet published ml-app-deployer, and a task was silently failing because the command wasn't found. An error is much better in that scenario.
1 parent 0874c6d commit 1b055d5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main/groovy/com/marklogic/gradle/task/MarkLogicTask.groovy

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.marklogic.client.DatabaseClient
99
import com.marklogic.mgmt.ManageClient
1010
import com.marklogic.mgmt.admin.AdminManager
1111
import org.gradle.api.DefaultTask
12+
import org.gradle.api.GradleException
1213
import org.gradle.api.tasks.Internal
1314

1415
/**
@@ -101,13 +102,22 @@ class MarkLogicTask extends DefaultTask {
101102
return deployer
102103
}
103104

105+
Command getCommandWithClassName(String className) {
106+
SimpleAppDeployer d = (SimpleAppDeployer)getAppDeployer()
107+
Command command = d.getCommand(className)
108+
// New in 4.4.0 - before, null was returned and no command was run, which would be very unexpected when the
109+
// caller is asking to run a specific command.
110+
if (command == null) {
111+
throw new GradleException("No command found with class name: " + className)
112+
}
113+
return command
114+
}
115+
104116
void invokeDeployerCommandWithClassName(String className) {
105-
SimpleAppDeployer d = (SimpleAppDeployer)getAppDeployer()
106-
new SimpleAppDeployer(getManageClient(), getAdminManager(), d.getCommand(className)).deploy(getAppConfig())
117+
new SimpleAppDeployer(getManageClient(), getAdminManager(), getCommandWithClassName(className)).deploy(getAppConfig())
107118
}
108119

109120
void undeployWithCommandWithClassName(String className) {
110-
SimpleAppDeployer d = (SimpleAppDeployer)getAppDeployer()
111-
new SimpleAppDeployer(getManageClient(), getAdminManager(), d.getCommand(className)).undeploy(getAppConfig())
121+
new SimpleAppDeployer(getManageClient(), getAdminManager(), getCommandWithClassName(className)).undeploy(getAppConfig())
112122
}
113123
}

0 commit comments

Comments
 (0)