Skip to content

Commit d897e3f

Browse files
authored
Fix "The field value for ExceptionMessage__c is too long" exception for long flow error messages (#828)
* Fix #827 by truncating the passed in fault message properly prior to publishing the saved LogEntryEvent__e
1 parent daf14e9 commit d897e3f

7 files changed

Lines changed: 44 additions & 16 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
The most robust observability solution for Salesforce experts. Built 100% natively on the platform, and designed to work seamlessly with Apex, Lightning Components, Flow, OmniStudio, and integrations.
77

8-
## Unlocked Package - v4.15.3
8+
## Unlocked Package - v4.15.4
99

10-
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015ok2QAA)
11-
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015ok2QAA)
10+
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oklQAA)
11+
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015oklQAA)
1212
[![View Documentation](./images/btn-view-documentation.png)](https://github.com/jongpie/NebulaLogger/wiki)
1313

14-
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015ok2QAA`
14+
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y0000015oklQAA`
1515

1616
---
1717

nebula-logger/core/main/logger-engine/classes/FlowLogger.cls

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ public inherited sharing class FlowLogger {
108108

109109
// Set the logging level if it's blank
110110
if (String.isBlank(this.loggingLevelName)) {
111-
if (String.isNotBlank(this.faultMessage)) {
112-
this.loggingLevelName = System.LoggingLevel.ERROR.name();
113-
} else {
114-
this.loggingLevelName = System.LoggingLevel.DEBUG.name();
115-
}
111+
this.loggingLevelName = (String.isNotBlank(this.faultMessage) ? System.LoggingLevel.ERROR : System.LoggingLevel.DEBUG).name();
116112
}
117113

118114
// In Flow, using comma-separated String is easier than List<String>
@@ -148,7 +144,10 @@ public inherited sharing class FlowLogger {
148144
//
149145
// TODO Need to revisit this to see if there is a way to determine this programatically, or if new
150146
// Flow parameter(s) would be needed.
151-
this.logEntryEvent.ExceptionMessage__c = hasFaultMessage ? this.faultMessage : FLOW_FAULT_ERROR_DEFAULT_EXCEPTION_MESSAGE;
147+
this.logEntryEvent.ExceptionMessage__c = LoggerDataStore.truncateFieldValue(
148+
Schema.LogEntryEvent__e.ExceptionMessage__c,
149+
hasFaultMessage ? this.faultMessage : FLOW_FAULT_ERROR_DEFAULT_EXCEPTION_MESSAGE
150+
);
152151
this.logEntryEvent.ExceptionSourceApiName__c = this.flowName;
153152
this.logEntryEvent.ExceptionSourceMetadataType__c = FLOW_SOURCE_METADATA_TYPE;
154153
this.logEntryEvent.ExceptionType__c = FLOW_EXCEPTION_TYPE_NAME;

nebula-logger/core/main/logger-engine/classes/Logger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
global with sharing class Logger {
1616
// There's no reliable way to get the version number dynamically in Apex
1717
@TestVisible
18-
private static final String CURRENT_VERSION_NUMBER = 'v4.15.3';
18+
private static final String CURRENT_VERSION_NUMBER = 'v4.15.4';
1919
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
2020
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
2121
private static final String MISSING_SCENARIO_ERROR_MESSAGE = 'No logger scenario specified. A scenario is required for logging in this org.';

nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LoggerServiceTaskQueue from './loggerServiceTaskQueue';
1010
import getSettings from '@salesforce/apex/ComponentLogger.getSettings';
1111
import saveComponentLogEntries from '@salesforce/apex/ComponentLogger.saveComponentLogEntries';
1212

13-
const CURRENT_VERSION_NUMBER = 'v4.15.3';
13+
const CURRENT_VERSION_NUMBER = 'v4.15.4';
1414

1515
const CONSOLE_OUTPUT_CONFIG = {
1616
messagePrefix: `%c Nebula Logger ${CURRENT_VERSION_NUMBER} `,

nebula-logger/core/tests/logger-engine/classes/FlowLogger_Tests.cls

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,32 @@ private class FlowLogger_Tests {
245245
System.Assert.isNull(publishedLogEntryEvent.StackTrace__c, 'Flow does not have a stack trace, so expect null');
246246
System.Assert.areEqual(flowEntry.timestamp, publishedLogEntryEvent.Timestamp__c);
247247
}
248+
249+
@IsTest
250+
static void it_truncates_too_long_exception_messages() {
251+
LoggerDataStore.setMock(LoggerMockDataStore.getEventBus());
252+
System.LoggingLevel entryLoggingLevel = System.LoggingLevel.ERROR;
253+
Logger.getUserSettings().LoggingLevel__c = entryLoggingLevel.name();
254+
LoggerTestConfigurator.setupMockSObjectHandlerConfigurations();
255+
Integer maxLengthForExceptionMessage = Schema.LogEntryEvent__e.ExceptionMessage__c.getDescribe().getLength();
256+
FlowLogger.LogEntry flowEntry = new FlowLogger.LogEntry();
257+
flowEntry.flowName = 'MyFlow';
258+
flowEntry.message = 'hello from Flow';
259+
flowEntry.loggingLevelName = entryLoggingLevel.name();
260+
flowEntry.saveLog = true;
261+
flowEntry.faultMessage = '0'.repeat(maxLengthForExceptionMessage + 1);
262+
flowEntry.timestamp = System.now();
263+
System.Assert.areEqual(0, Logger.saveLogCallCount);
264+
System.Assert.areEqual(0, LoggerMockDataStore.getEventBus().getPublishCallCount());
265+
System.Assert.areEqual(0, LoggerMockDataStore.getEventBus().getPublishedPlatformEvents().size());
266+
267+
FlowLogger.addEntries(new List<FlowLogger.LogEntry>{ flowEntry });
268+
269+
System.Assert.areEqual(0, Logger.getBufferSize());
270+
System.Assert.areEqual(1, Logger.saveLogCallCount);
271+
System.Assert.areEqual(1, LoggerMockDataStore.getEventBus().getPublishCallCount());
272+
System.Assert.areEqual(1, LoggerMockDataStore.getEventBus().getPublishedPlatformEvents().size());
273+
LogEntryEvent__e publishedLogEntryEvent = (LogEntryEvent__e) LoggerMockDataStore.getEventBus().getPublishedPlatformEvents().get(0);
274+
System.Assert.areEqual(maxLengthForExceptionMessage, publishedLogEntryEvent.ExceptionMessage__c.length());
275+
}
248276
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nebula-logger",
3-
"version": "4.15.3",
3+
"version": "4.15.4",
44
"description": "The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.",
55
"author": "Jonathan Gillespie",
66
"license": "MIT",

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"path": "./nebula-logger/core",
1010
"definitionFile": "./config/scratch-orgs/base-scratch-def.json",
1111
"scopeProfiles": true,
12-
"versionNumber": "4.15.3.NEXT",
13-
"versionName": "Improved Testability of Queries",
14-
"versionDescription": "Enhanced the internals of the existing selector classes LoggerEngineDataSelector and LogManagementDataSelector + introducted a new class LoggerConfigurationSelector to provide improve testability of queries",
12+
"versionNumber": "4.15.4.NEXT",
13+
"versionName": "FlowLogger exception message handling",
14+
"versionDescription": "FlowLogger now properly truncates the LogEntryEvent__e.ExceptionMessage__c field",
1515
"postInstallUrl": "https://github.com/jongpie/NebulaLogger/wiki",
1616
"releaseNotesUrl": "https://github.com/jongpie/NebulaLogger/releases",
1717
"unpackagedMetadata": {
@@ -208,6 +208,7 @@
208208
"Nebula Logger - Core@4.15.1-system.orglimits-optimisations": "04t5Y0000015ohhQAA",
209209
"Nebula Logger - Core@4.15.2-added-support-for-logging-emptyrecylebinresult": "04t5Y0000015oifQAA",
210210
"Nebula Logger - Core@4.15.3-improved-testability-of-queries": "04t5Y0000015ok2QAA",
211+
"Nebula Logger - Core@4.15.4-flowlogger-exception-message-handling": "04t5Y0000015oklQAA",
211212
"Nebula Logger - Core Plugin - Async Failure Additions": "0Ho5Y000000blO4SAI",
212213
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.0": "04t5Y0000015lhiQAA",
213214
"Nebula Logger - Core Plugin - Async Failure Additions@1.0.1": "04t5Y0000015lhsQAA",

0 commit comments

Comments
 (0)