Skip to content

Commit

Permalink
Adding a temporary fix for the P JsonFormatter Exception (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushdesai authored Nov 25, 2023
1 parent c39bb02 commit 2f3eff7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 14 additions & 6 deletions Src/PChecker/CheckerCore/Actors/Logging/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void HandleLogEntry(LogEntry logEntry)
// For MonitorProcessEvents, tie it to the senderMachine's current vector clock
// so that there is some association in the timeline
case "MonitorProcessEvent":
updateMachineVcMap(machine, _contextVcMap[logDetails.Sender]);
if (logDetails.Sender != null) updateMachineVcMap(machine, _contextVcMap[logDetails.Sender]);
break;

// On dequeue OR receive event, has the string containing information about the current machine that dequeued (i.e. received the event),
Expand Down Expand Up @@ -712,13 +712,21 @@ public enum LogType
/// <param name="updateVcMap">Of type Bool: If true, run HandleLogEntry to get vector clock. Else, don't.</param>
public void AddToLogs(bool updateVcMap = false)
{
if (updateVcMap)
try
{
_vcGenerator.HandleLogEntry(_log);
}
if (updateVcMap)
{
_vcGenerator.HandleLogEntry(_log);
}

_logs.Add(_log);
_log = new LogEntry();
_logs.Add(_log);
_log = new LogEntry();
}
catch (Exception)
{
// ignoring exceptions in logger.
// TODO: this needs to be fixed.
}
}
}
}
10 changes: 3 additions & 7 deletions Src/PRuntimes/PCSharpRuntime/PJsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@ namespace Plang.CSharpRuntime
/// </summary>
public class PJsonFormatter : ActorRuntimeLogJsonFormatter
{
public PJsonFormatter() : base()
{
}

/// <summary>
/// Removes the '<' and '>' tags for a log text.
/// I.e., '<ErrorLog> Some error log...' becomes 'Some error log...'
/// </summary>
/// <param name="log">The text log</param>
/// <returns>New string with the tag removed or just the string itself if there is no tag.</returns>
private static string RemoveLogTag(string log)
{
var openingTagIndex = log.IndexOf("<");
var closingTagIndex = log.IndexOf(">");
var openingTagIndex = log.IndexOf("<", StringComparison.Ordinal);
var closingTagIndex = log.IndexOf(">", StringComparison.Ordinal);
var potentialTagExists = openingTagIndex != -1 && closingTagIndex != -1;
var validOpeningTag = openingTagIndex == 0 && closingTagIndex > openingTagIndex;

Expand Down Expand Up @@ -87,7 +83,7 @@ private static object GetEventPayloadInJson(Event e)
}

var pe = (PEvent)(e);
return pe.Payload == null ? null : pe.Payload.ToDict();
return pe.Payload?.ToDict();
}

public override void OnCompleted()
Expand Down

0 comments on commit 2f3eff7

Please sign in to comment.