Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

chore(items): log failures when activating a method version (#1683)

Naveen Kashyapd3cb1e4e7a32
diff --git a/apps/erp/app/routes/x+/items+/methods+/versions.activate.$id.tsx b/apps/erp/app/routes/x+/items+/methods+/versions.activate.$id.tsx
index 9b7c94f2dd..844442b321 100644
--- a/apps/erp/app/routes/x+/items+/methods+/versions.activate.$id.tsx
+++ b/apps/erp/app/routes/x+/items+/methods+/versions.activate.$id.tsx
@@ -2,12 +2,15 @@ import { assertIsPost, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { getCarbonServiceRole } from "@carbon/auth/client.server";
import { flash } from "@carbon/auth/session.server";
+import { getLogger } from "@carbon/logger";
import type { ActionFunctionArgs } from "react-router";
import { redirect } from "react-router";
import { checkRevisionLock } from "~/modules/items/items.server";
import { activateMethodVersion } from "~/modules/items/items.service";
import { requestReferrer } from "~/utils/path";
+const logger = getLogger("erp", "items");
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { companyId, userId } = await requirePermissions(request, {
@@ -19,6 +22,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { id } = params;
if (!id) {
+ logger.warning("Method version activation called without an id");
return { success: false, message: "Invalid operation tool id" };
}
@@ -26,6 +30,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
// BOM/BOP, so a missing query param or referrer must fail without having
// already flipped the method.
if (!methodToReplace) {
+ logger.warning("Method version activation missing methodToReplace", {
+ methodVersionId: id
+ });
return {
success: false,
message: "Method to replace is required"
@@ -35,6 +42,18 @@ export async function action({ request, params }: ActionFunctionArgs) {
const redirectPath = requestReferrer(request)?.replace(methodToReplace, id);
if (!redirectPath) {
+ // requestReferrer returns null when the Referer is missing or its origin
+ // differs from request.url's — behind a proxy the server can see an
+ // internal scheme/host, which rejects every same-site referrer.
+ logger.warning("Method version activation could not resolve a redirect", {
+ methodVersionId: id,
+ methodToReplace,
+ referer: request.headers.get("referer"),
+ requestUrl: request.url,
+ host: request.headers.get("host"),
+ forwardedHost: request.headers.get("x-forwarded-host"),
+ forwardedProto: request.headers.get("x-forwarded-proto")
+ });
return {
success: false,
message: "Failed to redirect to the correct page"
@@ -51,6 +70,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
companyId
});
if (!lock.ok) {
+ logger.warning("Method version activation blocked by revision lock", {
+ methodVersionId: id,
+ companyId,
+ reason: lock.message
+ });
return { success: false, message: lock.message };
}
@@ -65,6 +89,11 @@ export async function action({ request, params }: ActionFunctionArgs) {
});
if (update.error) {
+ logger.error("Failed to activate method version", {
+ methodVersionId: id,
+ companyId,
+ error: update.error
+ });
return {
success: false,
message: "Failed to activate method version"