blob: 9c783c5172db6d2809c8dedd6ce1b7fb226ec7f2 [file] [log] [blame]
Shawn McCarney79a0b102020-03-26 23:49:02 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <exception>
19#include <filesystem>
20#include <string>
21
22namespace phosphor::power::regulators
23{
24
25/**
26 * @class ConfigFileParserError
27 *
28 * An error that occurred while parsing the JSON configuration file that
29 * controls the phosphor-regulators application.
30 */
31class ConfigFileParserError : public std::exception
32{
33 public:
34 // Specify which compiler-generated methods we want
35 ConfigFileParserError() = delete;
36 ConfigFileParserError(const ConfigFileParserError&) = default;
37 ConfigFileParserError(ConfigFileParserError&&) = default;
38 ConfigFileParserError& operator=(const ConfigFileParserError&) = default;
39 ConfigFileParserError& operator=(ConfigFileParserError&&) = default;
40 virtual ~ConfigFileParserError() = default;
41
42 /**
43 * Constructor.
44 *
45 * @param pathName configuration file path name
46 * @param error error message
47 */
48 explicit ConfigFileParserError(const std::filesystem::path& pathName,
49 const std::string& error) :
50 pathName{pathName},
51 error{"ConfigFileParserError: " + pathName.string() + ": " + error}
Adriana Kobylak0c9a33d2021-09-13 18:05:09 +000052 {}
Shawn McCarney79a0b102020-03-26 23:49:02 -050053
54 /**
55 * Returns the configuration file path name.
56 *
57 * @return path name
58 */
59 const std::filesystem::path& getPathName()
60 {
61 return pathName;
62 }
63
64 /**
65 * Returns the description of this error.
66 *
67 * @return error description
68 */
69 const char* what() const noexcept override
70 {
71 return error.c_str();
72 }
73
74 private:
75 /**
76 * Configuration file path name.
77 */
78 const std::filesystem::path pathName;
79
80 /**
81 * Error message.
82 */
83 const std::string error{};
84};
85
86} // namespace phosphor::power::regulators