Skip to content

Commit

Permalink
Add sentry breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec committed Mar 18, 2020
1 parent 4c7cc70 commit 1a02b72
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
7 changes: 5 additions & 2 deletions src/Lurker/ClientLurker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,13 @@ private void OnFileChanged(string newline)
}
catch (Exception ex)
{
var exception = new Exception($"Line in error: {newline}", ex);
var lineError = $"Line in error: {newline}";
var exception = new Exception(lineError, ex);
Logger.Error(exception, exception.Message);

#if (!DEBUG)
SentrySdk.CaptureException(exception);
SentrySdk.AddBreadcrumb(message: lineError, level: BreadcrumbLevel.Error);
SentrySdk.CaptureException(ex);
#endif
}
}
Expand Down
94 changes: 54 additions & 40 deletions src/Lurker/Events/TradeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,48 +155,55 @@ public static bool IsTradeMessage(string message)
/// <returns>The item location</returns>
public Location ParseLocation(string locationValue)
{
var locationMarkerIndex = locationValue.IndexOf(LocationMarker);
var locationMarkerEndIndex = locationValue.IndexOf(LocationMarkerEnd);
if (locationMarkerIndex == -1 || locationMarkerEndIndex == -1)
try
{
return new Location();
}
var locationMarkerIndex = locationValue.IndexOf(LocationMarker);
var locationMarkerEndIndex = locationValue.IndexOf(LocationMarkerEnd);
if (locationMarkerIndex == -1 || locationMarkerEndIndex == -1)
{
return new Location();
}

// tab name
var tabValue = locationValue.GetLineBefore("\";");
var index = tabValue.IndexOf("\"");
var stashTabName = tabValue.Substring(index + 1);
// tab name
var tabValue = locationValue.GetLineBefore("\";");
var index = tabValue.IndexOf("\"");
var stashTabName = tabValue.Substring(index + 1);

// Position
var positionValue = locationValue.GetLineAfter("\";");
var positionIndex = positionValue.IndexOf(PositionMarker);
// Position
var positionValue = locationValue.GetLineAfter("\";");
var positionIndex = positionValue.IndexOf(PositionMarker);

if (positionIndex != -1)
{
positionValue = positionValue.GetLineAfter("position: ");
}
if (positionIndex != -1)
{
positionValue = positionValue.GetLineAfter("position: ");
}

var positions = positionValue.Split(", ");
var leftValue = positions[0].GetLineAfter("left ");
var topValue = positions[1].GetLineAfter("top ");
var positions = positionValue.Split(", ");
var leftValue = positions[0].GetLineAfter("left ");
var topValue = positions[1].GetLineAfter("top ");

if (string.IsNullOrEmpty(leftValue) || string.IsNullOrEmpty(topValue))
{
return new Location()
{
StashTabName = stashTabName
};
}

var closingMarkerIndex = topValue.IndexOf(")");
topValue = topValue.Substring(0, closingMarkerIndex);

if (string.IsNullOrEmpty(leftValue) || string.IsNullOrEmpty(topValue))
{
return new Location()
{
StashTabName = stashTabName
StashTabName = stashTabName,
Left = Convert.ToInt32(leftValue),
Top = Convert.ToInt32(topValue),
};
}

var closingMarkerIndex = topValue.IndexOf(")");
topValue = topValue.Substring(0, closingMarkerIndex);

return new Location()
catch
{
StashTabName = stashTabName,
Left = Convert.ToInt32(leftValue),
Top = Convert.ToInt32(topValue),
};
return new Location();
}
}

/// <summary>
Expand All @@ -206,19 +213,26 @@ public Location ParseLocation(string locationValue)
/// <returns>The price of the offer.</returns>
public Price ParsePrice(string priceValue)
{
var values = priceValue.Split(' ');
if (!double.TryParse(values[0], out _))
try
{
return new Price();
}
var values = priceValue.Split(' ');
if (!double.TryParse(values[0], out _))
{
return new Price();
}

var currencyTypeValue = string.Join(" ", values.Skip(1));
var currencyTypeValue = string.Join(" ", values.Skip(1));

return new Price()
return new Price()
{
NumberOfCurrencies = double.Parse(values[0], CultureInfo.InvariantCulture),
CurrencyType = CurrencyTypeParser.Parse(currencyTypeValue),
};
}
catch
{
NumberOfCurrencies = double.Parse(values[0], CultureInfo.InvariantCulture),
CurrencyType = CurrencyTypeParser.Parse(currencyTypeValue),
};
return new Price();
}
}

/// <summary>
Expand Down

0 comments on commit 1a02b72

Please sign in to comment.