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.

fix(purchasing): log every failure path in the planning order action (#1672)

Naveen Kashyapf6cb5b68e830
diff --git a/apps/erp/app/routes/x+/purchasing+/planning.update.tsx b/apps/erp/app/routes/x+/purchasing+/planning.update.tsx
index 11e049d1be..70726f3fdc 100644
--- a/apps/erp/app/routes/x+/purchasing+/planning.update.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/planning.update.tsx
@@ -30,6 +30,12 @@ export async function action({ request }: ActionFunctionArgs) {
const { items, action, locationId } = await request.json();
if (typeof locationId !== "string") {
+ logger.warn("Planning update rejected: locationId missing", {
+ companyId,
+ userId,
+ action,
+ locationIdType: typeof locationId
+ });
return data(
{
success: false,
@@ -40,6 +46,12 @@ export async function action({ request }: ActionFunctionArgs) {
}
if (typeof action !== "string") {
+ logger.warn("Planning update rejected: action missing", {
+ companyId,
+ userId,
+ locationId,
+ actionType: typeof action
+ });
return data(
{
success: false,
@@ -82,6 +94,13 @@ export async function action({ request }: ActionFunctionArgs) {
return error.message;
});
+ logger.warn("Planning order payload failed validation", {
+ companyId,
+ userId,
+ locationId,
+ errors: errorMessages,
+ issues: parsedItems.error.issues
+ });
return data(
{
success: false,
@@ -94,6 +113,11 @@ export async function action({ request }: ActionFunctionArgs) {
const itemsToOrder = parsedItems.data;
if (itemsToOrder.length === 0) {
+ logger.warn("Planning order payload had no items", {
+ companyId,
+ userId,
+ locationId
+ });
return data(
{
success: false,
@@ -464,6 +488,15 @@ export async function action({ request }: ActionFunctionArgs) {
}
if (errors.length > 0 && processedItems === 0) {
+ logger.error("Failed to process any planning orders", {
+ companyId,
+ userId,
+ locationId,
+ itemIds: Array.from(itemIds),
+ supplierIds: Array.from(supplierIds),
+ periodIds: Array.from(periodIds),
+ errors
+ });
return data(
{
success: false,
@@ -495,6 +528,27 @@ export async function action({ request }: ActionFunctionArgs) {
).values()
);
+ if (errors.length > 0) {
+ logger.warn("Planning orders processed with errors", {
+ companyId,
+ userId,
+ locationId,
+ processedItems,
+ totalItems: itemsToOrder.length,
+ purchaseOrderIds: purchaseOrders.map((po) => po.readableId),
+ errors
+ });
+ } else {
+ logger.info("Planning orders processed", {
+ companyId,
+ userId,
+ locationId,
+ processedItems,
+ totalItems: itemsToOrder.length,
+ purchaseOrderIds: purchaseOrders.map((po) => po.readableId)
+ });
+ }
+
return {
success: processedItems > 0,
message,
@@ -504,7 +558,12 @@ export async function action({ request }: ActionFunctionArgs) {
errors: errors.length > 0 ? errors : undefined
};
} catch (error) {
- logger.error("Unexpected error processing purchase orders", { error });
+ logger.error("Unexpected error processing purchase orders", {
+ companyId,
+ userId,
+ locationId,
+ error
+ });
return data(
{
success: false,
diff --git a/apps/erp/test/mcp-tool-metadata.test.ts b/apps/erp/test/mcp-tool-metadata.test.ts
index 35b0d5747b..611ae9eacc 100644
--- a/apps/erp/test/mcp-tool-metadata.test.ts
+++ b/apps/erp/test/mcp-tool-metadata.test.ts
@@ -272,11 +272,13 @@ describe("mcp tool-metadata generator", () => {
Object.keys(ruleBranches[0]?.properties ?? {}).length
).toBeGreaterThan(0);
+ // updateAbility takes an optional `name` and an optional cadence, so the
+ // published schema has both fields and no required list.
const ability = props(get("resources_updateAbility")).ability;
- expect(Object.keys(ability?.properties ?? {})).toContain(
- "recertifyEveryDays"
+ expect(Object.keys(ability?.properties ?? {})).toEqual(
+ expect.arrayContaining(["name", "recertifyEveryDays"])
);
- expect(ability?.required).toEqual(["recertifyEveryDays"]);
+ expect(ability?.required).toBeUndefined();
});
// Insert-vs-update discriminator, BOTH directions, gets a required `_operation`.