terminal/src/cascadia/TerminalApp/TerminalWarnings.h
Carlos Zamora 892cf05fe6
Add serialization error handling to settings projection layer (#7576)
Now that CascadiaSettings is a WinRT object, we need to update the error
handling a bit. Making it a WinRT object limits our errors to be
hresults. So we moved all the error handling down a layer to when we
load the settings object.

- Warnings encountered during validation are saved to `Warnings()`.
- Errors encountered during validation are saved to `GetLoadingError()`.
- Deserialization errors (mainly from JsonUtils) are saved to
  `GetDeserializationErrorMessage()`.

## References
#7141 - CascadiaSettings is a settings object
#885 - this makes ripping out CascadiaSettings into
     TerminalSettingsModel much easier

## Validation Steps Performed
* [x] Tests passed
- [x] Deployment succeeded
   - tested with invalid JSON (deserialization error)
   - tested with missing DefaultProfile (validation error)
2020-09-10 17:57:02 -07:00

43 lines
1.2 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- TerminalWarnings.h
Abstract:
- This file contains definitions for warnings, errors and exceptions used by the
Windows Terminal
Author(s):
- Mike Griese - August 2019
--*/
#pragma once
namespace winrt::TerminalApp::implementation
{
// This is a helper class to wrap up a SettingsLoadErrors into a proper
// exception type.
class SettingsException : public std::runtime_error
{
public:
explicit SettingsException(const SettingsLoadErrors& error) :
std::runtime_error{ nullptr },
_error{ error } {};
// We don't use the what() method - we want to be able to display
// localizable error messages. Catchers of this exception should use
// _GetErrorText (in App.cpp) to get the localized exception string.
const char* what() const override
{
return "Exception while loading or validating Terminal settings";
};
SettingsLoadErrors Error() const noexcept { return _error; };
private:
const SettingsLoadErrors _error;
};
};