Pass through uninstall error messages from backend (#22208)

# Checklist for submitter

- [x] Manual QA for all new/changed functionality

[See
Slack](https://fleetdm.slack.com/archives/C01EZVBHFHU/p1726605318985819?thread_ts=1726588126.583269&cid=C01EZVBHFHU)
from @noahtalerman for context
This commit is contained in:
Ian Littman
2024-09-18 11:22:22 -05:00
committed by GitHub
parent ea2a978733
commit f7fab000f8
2 changed files with 32 additions and 6 deletions
@@ -24,7 +24,7 @@ import Spinner from "components/Spinner";
import { generateSoftwareTableHeaders as generateHostSoftwareTableConfig } from "./HostSoftwareTableConfig";
import { generateSoftwareTableHeaders as generateDeviceSoftwareTableConfig } from "./DeviceSoftwareTableConfig";
import HostSoftwareTable from "./HostSoftwareTable";
import { getErrorMessage } from "./helpers";
import { getInstallErrorMessage, getUninstallErrorMessage } from "./helpers";
const baseClass = "software-card";
@@ -190,7 +190,7 @@ const HostSoftware = ({
"Software is installing or will install when the host comes online."
);
} catch (e) {
renderFlash("error", getErrorMessage(e));
renderFlash("error", getInstallErrorMessage(e));
}
setSoftwareIdActionPending(null);
refetchSoftware();
@@ -211,7 +211,7 @@ const HostSoftware = ({
</>
);
} catch (e) {
renderFlash("error", "Couldn't uninstall. Please try again.");
renderFlash("error", getUninstallErrorMessage(e));
}
setSoftwareIdActionPending(null);
refetchSoftware();
@@ -3,7 +3,10 @@ import { getErrorReason } from "interfaces/errors";
import { trimEnd, upperFirst } from "lodash";
const INSTALL_SOFTWARE_ERROR_PREFIX = "Couldn't install.";
const DEFAULT_ERROR_MESSAGE = `${INSTALL_SOFTWARE_ERROR_PREFIX} Please try again.`;
const DEFAULT_INSTALL_ERROR_MESSAGE = `${INSTALL_SOFTWARE_ERROR_PREFIX} Please try again.`;
const UNINSTALL_SOFTWARE_ERROR_PREFIX = "Couldn't uninstall.";
const DEFAULT_UNINSTALL_ERROR_MESSAGE = `${UNINSTALL_SOFTWARE_ERROR_PREFIX} Please try again.`;
const createOnlyInstallableOnMacOSMessage = (reason: string) =>
`Couldn't install. ${reason.replace("darwin", "macOS")}.`;
@@ -28,7 +31,7 @@ const showAPIMessage = (message: string) => {
};
// eslint-disable-next-line import/prefer-default-export
export const getErrorMessage = (e: unknown) => {
export const getInstallErrorMessage = (e: unknown) => {
const reason = upperFirst(trimEnd(getErrorReason(e), "."));
if (reason.includes("fleetd installed")) {
@@ -41,5 +44,28 @@ export const getErrorMessage = (e: unknown) => {
return reason;
}
return DEFAULT_ERROR_MESSAGE;
return DEFAULT_INSTALL_ERROR_MESSAGE;
};
// eslint-disable-next-line import/prefer-default-export
export const getUninstallErrorMessage = (e: unknown) => {
const reason = upperFirst(trimEnd(getErrorReason(e), "."));
if (
reason.includes("run script") ||
reason.includes("running script") ||
reason.includes("have fleetd") ||
reason.includes("only on")
) {
return `${UNINSTALL_SOFTWARE_ERROR_PREFIX} ${reason}.`;
} else if (reason.startsWith("Couldn't uninstall software.")) {
return reason.replace(
"Couldn't uninstall software.",
"Couldn't uninstall."
);
} else if (reason.startsWith("No uninstall script exists")) {
return `${UNINSTALL_SOFTWARE_ERROR_PREFIX}. An uninstall script does not exist for this package.`;
}
return DEFAULT_UNINSTALL_ERROR_MESSAGE;
};