mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: ensure stopping a workspace before starting it when updating (#22201)
Dynamic parameters were not following the same code path as legacy Closes https://github.com/coder/coder/issues/20333
This commit is contained in:
+37
-40
@@ -2389,44 +2389,23 @@ class ApiMethods {
|
||||
|
||||
const activeVersionId = template.active_version_id;
|
||||
|
||||
if (isDynamicParametersEnabled) {
|
||||
try {
|
||||
return await this.postWorkspaceBuild(workspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: activeVersionId,
|
||||
rich_parameter_values: newBuildParameters,
|
||||
});
|
||||
} catch (error) {
|
||||
// If the build failed because of a parameter validation error, then we
|
||||
// throw a special sentinel error that can be caught by the caller.
|
||||
if (
|
||||
isApiError(error) &&
|
||||
error.response.status === 400 &&
|
||||
error.response.data.validations &&
|
||||
error.response.data.validations.length > 0
|
||||
) {
|
||||
throw new ParameterValidationError(
|
||||
activeVersionId,
|
||||
error.response.data.validations,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
if (!isDynamicParametersEnabled) {
|
||||
// Dynamic templates rely on the backend to fully validate parameters.
|
||||
// Legacy templates do not, so do an additional check for any missing params.
|
||||
const templateParameters =
|
||||
await this.getTemplateVersionRichParameters(activeVersionId);
|
||||
|
||||
const missingParameters = getMissingParameters(
|
||||
oldBuildParameters,
|
||||
newBuildParameters,
|
||||
templateParameters,
|
||||
);
|
||||
|
||||
if (missingParameters.length > 0) {
|
||||
throw new MissingBuildParameters(missingParameters, activeVersionId);
|
||||
}
|
||||
}
|
||||
|
||||
const templateParameters =
|
||||
await this.getTemplateVersionRichParameters(activeVersionId);
|
||||
|
||||
const missingParameters = getMissingParameters(
|
||||
oldBuildParameters,
|
||||
newBuildParameters,
|
||||
templateParameters,
|
||||
);
|
||||
|
||||
if (missingParameters.length > 0) {
|
||||
throw new MissingBuildParameters(missingParameters, activeVersionId);
|
||||
}
|
||||
|
||||
// Stop the workspace if it is already running.
|
||||
if (workspace.latest_build.status === "running") {
|
||||
const stopBuild = await this.stopWorkspace(workspace.id);
|
||||
@@ -2440,11 +2419,29 @@ class ApiMethods {
|
||||
}
|
||||
}
|
||||
|
||||
return this.postWorkspaceBuild(workspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: activeVersionId,
|
||||
rich_parameter_values: newBuildParameters,
|
||||
});
|
||||
try {
|
||||
return await this.postWorkspaceBuild(workspace.id, {
|
||||
transition: "start",
|
||||
template_version_id: activeVersionId,
|
||||
rich_parameter_values: newBuildParameters,
|
||||
});
|
||||
} catch (error) {
|
||||
// If the build failed because of a parameter validation error, then we
|
||||
// throw a special sentinel error that can be caught by the caller.
|
||||
if (
|
||||
isDynamicParametersEnabled &&
|
||||
isApiError(error) &&
|
||||
error.response.status === 400 &&
|
||||
error.response.data.validations &&
|
||||
error.response.data.validations.length > 0
|
||||
) {
|
||||
throw new ParameterValidationError(
|
||||
activeVersionId,
|
||||
error.response.data.validations,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
getWorkspaceResolveAutostart = async (
|
||||
|
||||
Reference in New Issue
Block a user