* Helper function to log preprocessing errors to the database * * This ensures users can see why their workflow execution was blocked.
(params: {
workflowId: string
executionId: string
triggerType: string
requestId: string
userId: string
workspaceId: string
errorMessage: string
loggingSession?: LoggingSession
triggerData?: SessionStartParams['triggerData']
})
| 760 | * This ensures users can see why their workflow execution was blocked. |
| 761 | */ |
| 762 | async function logPreprocessingError(params: { |
| 763 | workflowId: string |
| 764 | executionId: string |
| 765 | triggerType: string |
| 766 | requestId: string |
| 767 | userId: string |
| 768 | workspaceId: string |
| 769 | errorMessage: string |
| 770 | loggingSession?: LoggingSession |
| 771 | triggerData?: SessionStartParams['triggerData'] |
| 772 | }): Promise<void> { |
| 773 | const { |
| 774 | workflowId, |
| 775 | executionId, |
| 776 | triggerType, |
| 777 | requestId, |
| 778 | userId, |
| 779 | workspaceId, |
| 780 | errorMessage, |
| 781 | loggingSession, |
| 782 | triggerData, |
| 783 | } = params |
| 784 | |
| 785 | if (!workspaceId) { |
| 786 | logger.warn(`[${requestId}] Cannot log preprocessing error: no workspaceId available`, { |
| 787 | workflowId, |
| 788 | executionId, |
| 789 | errorMessage, |
| 790 | }) |
| 791 | return |
| 792 | } |
| 793 | |
| 794 | try { |
| 795 | const session = |
| 796 | loggingSession || new LoggingSession(workflowId, executionId, triggerType, requestId) |
| 797 | |
| 798 | await session.safeStart({ |
| 799 | userId, |
| 800 | workspaceId, |
| 801 | variables: {}, |
| 802 | triggerData, |
| 803 | }) |
| 804 | |
| 805 | await session.safeCompleteWithError({ |
| 806 | error: { |
| 807 | message: errorMessage, |
| 808 | stackTrace: undefined, |
| 809 | }, |
| 810 | traceSpans: [], |
| 811 | skipCost: true, // Preprocessing errors should not charge - no execution occurred |
| 812 | }) |
| 813 | } catch (error) { |
| 814 | logger.error(`[${requestId}] Failed to log preprocessing error`, { |
| 815 | error, |
| 816 | workflowId, |
| 817 | executionId, |
| 818 | }) |
| 819 | // Don't throw - error logging should not block the error response |
no test coverage detected