mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 05:43:10 -07:00
handle errors
This commit is contained in:
parent
bce6ec10e4
commit
2c93865e7b
6 changed files with 23 additions and 12 deletions
|
@ -345,10 +345,9 @@ namespace CalculatorApp
|
|||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_RECALL_RESTORE), fields);
|
||||
}
|
||||
|
||||
void TraceLogger::LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String^ message)
|
||||
void TraceLogger::LogRecallError(Platform::String^ message)
|
||||
{
|
||||
auto fields = ref new LoggingFields();
|
||||
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
|
||||
fields->AddString(StringReference(L"FunctionName"), L"Recall");
|
||||
fields->AddString(StringReference(L"Message"), message);
|
||||
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields);
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace CalculatorApp::ViewModel::Common
|
|||
void LogPlatformExceptionInfo(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ message, int hresult);
|
||||
void LogRecallSnapshot(CalculatorApp::ViewModel::Common::ViewMode mode);
|
||||
void LogRecallRestore(CalculatorApp::ViewModel::Common::ViewMode mode);
|
||||
void LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ message);
|
||||
void LogRecallError(Platform::String ^ message);
|
||||
|
||||
internal:
|
||||
void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e);
|
||||
|
|
|
@ -5,6 +5,7 @@ using Windows.ApplicationModel.Activation;
|
|||
|
||||
using CalculatorApp.ViewModel.Snapshot;
|
||||
using CalculatorApp.JsonUtils;
|
||||
using CalculatorApp.ViewModel.Common;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
|
@ -42,8 +43,9 @@ namespace CalculatorApp
|
|||
var snapshot = JsonSerializer.Deserialize<ApplicationSnapshotAlias>(jsonStr);
|
||||
return new SnapshotLaunchArguments { HasError = false, Snapshot = snapshot.Value };
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger.GetInstance().LogRecallError($"Error occurs during the deserialization of Snapshot. Exception: {ex}");
|
||||
return new SnapshotLaunchArguments { HasError = true };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ namespace CalculatorApp
|
|||
public static string Decompress(byte[] data)
|
||||
{
|
||||
using (var srcStream = new MemoryStream(data))
|
||||
using (var deflateStream = new DeflateStream(srcStream, CompressionMode.Decompress))
|
||||
using (var inflater = new DeflateStream(srcStream, CompressionMode.Decompress))
|
||||
using (var resultStream = new MemoryStream())
|
||||
{
|
||||
deflateStream.CopyTo(resultStream);
|
||||
inflater.CopyTo(resultStream);
|
||||
byte[] decompressed = resultStream.ToArray();
|
||||
return Encoding.UTF8.GetString(decompressed);
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace CalculatorApp.JsonUtils
|
|||
get => Value.Command;
|
||||
set => Value.Command = value;
|
||||
}
|
||||
|
||||
public BinaryCommandAlias() => Value = new BinaryCommand();
|
||||
public BinaryCommandAlias(BinaryCommand value) => Value = value;
|
||||
}
|
||||
|
@ -114,6 +115,7 @@ namespace CalculatorApp.JsonUtils
|
|||
get => Value.Command;
|
||||
set => Value.Command = value;
|
||||
}
|
||||
|
||||
public ParenthesesAlias() => Value = new Parentheses();
|
||||
public ParenthesesAlias(Parentheses value) => Value = value;
|
||||
}
|
||||
|
@ -129,27 +131,25 @@ namespace CalculatorApp.JsonUtils
|
|||
get => Value.Tokens.Select(x => new CalcManagerHistoryTokenAlias(x));
|
||||
set => Value.Tokens = value.Select(Helpers.MapHistoryToken).ToList();
|
||||
}
|
||||
|
||||
[JsonPropertyName("c")]
|
||||
public IEnumerable<ICalcManagerIExprCommandAlias> Commands
|
||||
{
|
||||
get => Value.Commands.Select(Helpers.MapCommandAlias);
|
||||
set => Value.Commands = value.Select(Helpers.MapCommandAlias).ToList();
|
||||
}
|
||||
|
||||
[JsonPropertyName("e")]
|
||||
public string Expression
|
||||
{
|
||||
get => Value.Expression;
|
||||
set => Value.Expression = value;
|
||||
}
|
||||
|
||||
[JsonPropertyName("r")]
|
||||
public string Result
|
||||
{
|
||||
get => Value.Result;
|
||||
set => Value.Result = value;
|
||||
}
|
||||
|
||||
public CalcManagerHistoryItemAlias() => Value = new CalcManagerHistoryItem();
|
||||
public CalcManagerHistoryItemAlias(CalcManagerHistoryItem value) => Value = value;
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ namespace CalculatorApp
|
|||
var json = JsonSerializer.Serialize(new ApplicationSnapshotAlias(Model.Snapshot));
|
||||
embeddedData = Convert.ToBase64String(DeflateUtils.Compress(json));
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: trace errors
|
||||
TraceLogger.GetInstance().LogRecallError($"Error occurs during the serialization of Snapshot. Exception: {ex}");
|
||||
deferral.Complete();
|
||||
return;
|
||||
}
|
||||
|
@ -179,8 +179,18 @@ namespace CalculatorApp
|
|||
}
|
||||
else if (e.Parameter is SnapshotLaunchArguments snapshotArgs)
|
||||
{
|
||||
Model.RestoreFromSnapshot(snapshotArgs.Snapshot);
|
||||
Model.Initialize(initialMode);
|
||||
if (!snapshotArgs.HasError)
|
||||
{
|
||||
Model.RestoreFromSnapshot(snapshotArgs.Snapshot);
|
||||
TraceLogger.GetInstance().LogRecallRestore((ViewMode)snapshotArgs.Snapshot.Mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
|
||||
async () => await ShowSnapshotLaunchErrorAsync());
|
||||
TraceLogger.GetInstance().LogRecallError("OnNavigatedTo:Found errors.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue