diff --git a/packages/server/src/services/application.ts b/packages/server/src/services/application.ts index 179820b8f..719617322 100644 --- a/packages/server/src/services/application.ts +++ b/packages/server/src/services/application.ts @@ -142,11 +142,10 @@ export const updateApplication = async ( applicationId: string, applicationData: Partial, ) => { - const { appName, ...rest } = applicationData; const application = await db .update(applications) .set({ - ...rest, + ...applicationData, }) .where(eq(applications.applicationId, applicationId)) .returning(); @@ -237,12 +236,21 @@ export const deployApplication = async ({ } catch (error) { await updateDeploymentStatus(deployment.deploymentId, "error"); await updateApplicationStatus(applicationId, "error"); + + const errorMessage = + error instanceof Error + ? error.message + : String(error) || "Error building"; + // Truncate and sanitize error message for notifications + const sanitizedErrorMessage = errorMessage + .replace(/ghs_[a-zA-Z0-9]+/g, "ghs_***") // Hide GitHub tokens + .substring(0, 1500); // Truncate to avoid notification limits + await sendBuildErrorNotifications({ projectName: application.project.name, applicationName: application.name, applicationType: "application", - // @ts-ignore - errorMessage: error?.message || "Error building", + errorMessage: sanitizedErrorMessage, buildLink, organizationId: application.project.organizationId, }); @@ -370,8 +378,9 @@ export const deployRemoteApplication = async ({ domains: application.domains, }); } catch (error) { - // @ts-ignore - const encodedContent = encodeBase64(error?.message); + const errorMessage = error instanceof Error ? error.message : String(error); + + const encodedContent = encodeBase64(errorMessage); await execAsyncRemote( application.serverId, @@ -383,12 +392,12 @@ export const deployRemoteApplication = async ({ await updateDeploymentStatus(deployment.deploymentId, "error"); await updateApplicationStatus(applicationId, "error"); + await sendBuildErrorNotifications({ projectName: application.project.name, applicationName: application.name, applicationType: "application", - // @ts-ignore - errorMessage: error?.message || "Error building", + errorMessage: `Please check the logs for details: ${errorMessage}`, buildLink, organizationId: application.project.organizationId, }); diff --git a/packages/server/src/utils/notifications/build-error.ts b/packages/server/src/utils/notifications/build-error.ts index c873c9ab5..47fa4de77 100644 --- a/packages/server/src/utils/notifications/build-error.ts +++ b/packages/server/src/utils/notifications/build-error.ts @@ -65,6 +65,8 @@ export const sendBuildErrorNotifications = async ({ const decorate = (decoration: string, text: string) => `${discord.decoration ? decoration : ""} ${text}`.trim(); + const limitCharacter = 800; + const truncatedErrorMessage = errorMessage.substring(0, limitCharacter); await sendDiscordNotification(discord, { title: decorate(">", "`⚠️` Build Failed"), color: 0xed4245, @@ -101,7 +103,7 @@ export const sendBuildErrorNotifications = async ({ }, { name: decorate("`⚠️`", "Error Message"), - value: `\`\`\`${errorMessage}\`\`\``, + value: `\`\`\`${truncatedErrorMessage}\`\`\``, }, { name: decorate("`🧷`", "Build Link"),