function getErrorMessage(error) {
	// Lazy loading because this is used only if an error happened.
	const util = require("node:util");

	// Foolproof -- third-party module might throw non-object.
	if (typeof error !== "object" || error === null) {
		return String(error);
	}

	// Use templates if `error.messageTemplate` is present.
	if (typeof error.messageTemplate === "string") {
		try {
			const template = require(`../messages/${error.messageTemplate}.js`);

			return template(error.messageData || {});
		} catch {
			// Ignore template error then fallback to use `error.stack`.
		}
	}

	// Use the stacktrace if it's an error object.
	if (typeof error.stack === "string") {
		return error.stack;
	}

	// Otherwise, dump the object.
	return util.format("%o", error);
}
Get the error message of a given value.
@param {any} error The value to get.
@returns {string} The error message.