blob: 8b3e16e396672753faa5b7f43d23b16759581f3a [file] [log] [blame]
Shawn McCarney6a957f62024-01-10 16:15:19 -06001/**
Shawn McCarney38f85002025-10-31 17:59:36 -05002 * Copyright © 2025 IBM Corporation
Shawn McCarney6a957f62024-01-10 16:15:19 -06003 *
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
Shawn McCarney38f85002025-10-31 17:59:36 -050022namespace phosphor::power::util
Shawn McCarney6a957f62024-01-10 16:15:19 -060023{
24
25/**
26 * @class ConfigFileParserError
27 *
28 * An error that occurred while parsing a JSON configuration file.
29 */
30class ConfigFileParserError : public std::exception
31{
32 public:
33 // Specify which compiler-generated methods we want
34 ConfigFileParserError() = delete;
35 ConfigFileParserError(const ConfigFileParserError&) = default;
36 ConfigFileParserError(ConfigFileParserError&&) = default;
37 ConfigFileParserError& operator=(const ConfigFileParserError&) = default;
38 ConfigFileParserError& operator=(ConfigFileParserError&&) = default;
39 virtual ~ConfigFileParserError() = default;
40
41 /**
42 * Constructor.
43 *
44 * @param pathName Configuration file path name
45 * @param error Error message
46 */
47 explicit ConfigFileParserError(const std::filesystem::path& pathName,
48 const std::string& error) :
49 pathName{pathName},
50 error{"ConfigFileParserError: " + pathName.string() + ": " + error}
51 {}
52
53 /**
54 * Returns the configuration file path name.
55 *
56 * @return path name
57 */
58 const std::filesystem::path& getPathName()
59 {
60 return pathName;
61 }
62
63 /**
64 * Returns the description of this error.
65 *
66 * @return error description
67 */
68 const char* what() const noexcept override
69 {
70 return error.c_str();
71 }
72
73 private:
74 /**
75 * Configuration file path name.
76 */
77 const std::filesystem::path pathName;
78
79 /**
80 * Error message.
81 */
82 const std::string error{};
83};
84
Shawn McCarney38f85002025-10-31 17:59:36 -050085} // namespace phosphor::power::util