Skip to content

Commit

Permalink
Fixed some issues with exception-throwing in FlowLogger, updated some…
Browse files Browse the repository at this point in the history
… ApexDocs comments in Logger
  • Loading branch information
jongpie committed Aug 7, 2023
1 parent 6ae0be8 commit e8686e0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.sf/
.sfdx/
.vscode/
docs/apex/Miscellaneous/
# nebula-logger/**/main/default/
# tests/
test-coverage/
Expand Down
32 changes: 16 additions & 16 deletions docs/apex/Logger-Engine/Logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -1494,97 +1494,97 @@ The new entry's instance of `LogEntryEventBuilder`, useful for chaining met

#### `exception(LogMessage logMessage, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------------------------- |
| `logMessage` | The instance of `LogMessage` to use to set the entry's message field |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(LogMessage logMessage, Id recordId, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------------------------- |
| `logMessage` | The instance of `LogMessage` to use to set the entry's message field |
| `recordId` | The record ID of an `SObject` to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(LogMessage logMessage, SObject record, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------------------------- |
| `logMessage` | The instance of `LogMessage` to use to set the entry's message field |
| `record` | The `SObject` record to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(LogMessage logMessage, List<SObject> records, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------------------------- |
| `logMessage` | The instance of `LogMessage` to use to set the entry&apos;s message field |
| `records` | The list of `SObject` records to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(String message, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------- |
| `message` | The string to use to set the entry&apos;s message field |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(String message, Id recordId, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------- |
| `message` | The string to use to set the entry&apos;s message field |
| `recordId` | The record ID of an `SObject` to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(String message, SObject record, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------- |
| `message` | The string to use to set the entry&apos;s message field |
| `record` | The `SObject` record to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `exception(String message, List<SObject> records, System.Exception apexException)``void`

Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
Creates a new log entry with logging level == `System.LoggingLevel.ERROR`, automatically saves the log, and then throws the provided exception

##### Parameters

| Param | Description |
| --------------- | ------------------------------------------------------------------------- |
| `message` | The instance of `LogMessage` to use to set the entry&apos;s message field |
| `records` | The list of `SObject` records to log |
| `apexException` | The instance of `System.Exception` to log |
| `apexException` | The instance of `System.Exception` to log and throw |

#### `fine(LogMessage logMessage, Database.LeadConvertResult leadConvertResult)``LogEntryEventBuilder`

Expand Down
25 changes: 15 additions & 10 deletions nebula-logger/core/main/logger-engine/classes/FlowLogger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* @see LogEntryEventBuilder
*/
public inherited sharing class FlowLogger {
private static final String FLOW_EXCEPTION_TYPE_NAME = 'Flow.FaultError';
@TestVisible
private static final String FLOW_FAULT_ERROR_DEFAULT_EXCEPTION_MESSAGE = 'An unknown Flow exception has occurred';

static {
Logger.ignoreOrigin(FlowLogger.class);
}
Expand Down Expand Up @@ -128,7 +132,7 @@ public inherited sharing class FlowLogger {

if (String.isNotBlank(this.faultMessage)) {
this.logEntryEvent.ExceptionMessage__c = this.faultMessage;
this.logEntryEvent.ExceptionType__c = 'Flow.FaultError';
this.logEntryEvent.ExceptionType__c = FLOW_EXCEPTION_TYPE_NAME;
}

return this.logEntryEventBuilder;
Expand All @@ -146,7 +150,7 @@ public inherited sharing class FlowLogger {
Boolean saveLog = false;
Logger.SaveMethod saveMethod = Logger.getSaveMethod();
Boolean shouldThrowFaultMessageException = false;
String faultMessage = '';
String faultMessage = FLOW_FAULT_ERROR_DEFAULT_EXCEPTION_MESSAGE;

for (LogEntry flowEntry : flowEntries) {
flowEntry.addToLoggerBuffer();
Expand All @@ -156,22 +160,23 @@ public inherited sharing class FlowLogger {
if (String.isNotBlank(flowEntry.saveMethodName) == true) {
saveMethod = Logger.SaveMethod.valueOf(flowEntry.saveMethodName);
}
if (flowEntry.shouldThrowFaultMessageException == true) {
shouldThrowFaultMessageException = flowEntry.shouldThrowFaultMessageException;
}
if (String.isNotBlank(flowEntry.faultMessage) == true) {
faultMessage = flowEntry.faultMessage;
}
}
if (String.isNotBlank(flowEntry.faultMessage) == true) {
faultMessage = flowEntry.faultMessage;
}
if (flowEntry.shouldThrowFaultMessageException == true) {
shouldThrowFaultMessageException = flowEntry.shouldThrowFaultMessageException;
}
}

if (saveLog == true) {
Logger.saveLog(saveMethod);
}

// Here we throw an exception so we stop synchronous database updates from happening
// avoiding inconsistencies
// Here we throw an exception so we stop synchronous database updates from happening,
// avoiding inconsistencies in the data
if (shouldThrowFaultMessageException == true) {
Logger.saveLog(Logger.SaveMethod.EVENT_BUS);
throw new System.FlowException(faultMessage);
}

Expand Down
42 changes: 25 additions & 17 deletions nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ global with sharing class Logger {

// Exception methods - these all use ERROR logging level & automatically save & throw the provided exception
/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, System.Exception apexException) {
error().setExceptionDetails(apexException).setMessage(logMessage);
Expand All @@ -401,10 +402,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, Id recordId, System.Exception apexException) {
error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(logMessage);
Expand All @@ -413,10 +415,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, SObject record, System.Exception apexException) {
error().setRecordId(record).setExceptionDetails(apexException).setMessage(logMessage);
Expand All @@ -425,10 +428,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param logMessage The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(LogMessage logMessage, List<SObject> records, System.Exception apexException) {
error().setRecord(records).setExceptionDetails(apexException).setMessage(logMessage);
Expand All @@ -437,9 +441,10 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, System.Exception apexException) {
error().setExceptionDetails(apexException).setMessage(message);
Expand All @@ -448,10 +453,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param recordId The record ID of an `SObject` to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, Id recordId, System.Exception apexException) {
error().setRecordId(recordId).setExceptionDetails(apexException).setMessage(message);
Expand All @@ -460,10 +466,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The string to use to set the entry's message field
* @param record The `SObject` record to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, SObject record, System.Exception apexException) {
error().setRecordId(record).setExceptionDetails(apexException).setMessage(message);
Expand All @@ -472,10 +479,11 @@ global with sharing class Logger {
}

/**
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`
* @param message The instance of `LogMessage` to use to set the entry's message field
* @description Creates a new log entry with logging level == `System.LoggingLevel.ERROR`,
* automatically saves the log, and then throws the provided exception
* @param message The instance of `LogMessage` to use to set the entry's message field
* @param records The list of `SObject` records to log
* @param apexException The instance of `System.Exception` to log
* @param apexException The instance of `System.Exception` to log and throw
*/
global static void exception(String message, List<SObject> records, System.Exception apexException) {
error().setRecord(records).setExceptionDetails(apexException).setMessage(message);
Expand Down
Loading

0 comments on commit e8686e0

Please sign in to comment.