Skip to content

Commit

Permalink
Update SemanticChatMemoryItem.cs (microsoft#542)
Browse files Browse the repository at this point in the history
### Motivation and Context

  1. Why is this change required?  Possible Null reference exception.
2. What problem does it solve? Fix null reference in ToFormattedString
function
3. What scenario does it contribute to? If ( Item ) object label and
Details are null.

### Description

In the `SemanticChatMemoryItem.ToFormattedString` function, ensure that
the `Details` property is not null before trimming it. This change
prevents potential NullReferenceExceptions when the `Details` property
is null.

This modification ensures the stability of the `ToFormattedString`
function when used in other parts of the code.

### Contribution Checklist

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
Ahmed-Adel3 authored and Ryangr0 committed Oct 26, 2023
1 parent edbc492 commit 4f98734
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion webapi/Skills/ChatSkills/SemanticChatMemoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public SemanticChatMemoryItem(string label, string details)
/// <returns>A formatted string representing the item.</returns>
public string ToFormattedString()
{
return $"{this.Label}: {this.Details.Trim()}";
return $"{this.Label}: {this.Details?.Trim()}";
}
}

0 comments on commit 4f98734

Please sign in to comment.