| 143 | |
| 144 | |
| 145 | Poco::AutoPtr<Poco::XML::Document> YAMLParser::parse(const String& path) |
| 146 | { |
| 147 | YAML::Node node_yml; |
| 148 | try |
| 149 | { |
| 150 | node_yml = YAML::LoadFile(path); |
| 151 | } |
| 152 | catch (const YAML::ParserException& e) |
| 153 | { |
| 154 | /// yaml-cpp cannot parse the file because its contents are incorrect |
| 155 | throw Exception(ErrorCodes::CANNOT_PARSE_YAML, "Unable to parse YAML configuration file {}, {}", path, e.what()); |
| 156 | } |
| 157 | catch (const YAML::BadFile&) |
| 158 | { |
| 159 | /// yaml-cpp cannot open the file even though it exists |
| 160 | throw Exception(ErrorCodes::CANNOT_OPEN_FILE, "Unable to open YAML configuration file {}", path); |
| 161 | } |
| 162 | Poco::AutoPtr<Poco::XML::Document> xml = new Document; |
| 163 | Poco::AutoPtr<Poco::XML::Element> root_node = xml->createElement("clickhouse"); |
| 164 | xml->appendChild(root_node); |
| 165 | try |
| 166 | { |
| 167 | processNode(node_yml, *root_node); |
| 168 | } |
| 169 | catch (const YAML::TypedBadConversion<std::string>&) |
| 170 | { |
| 171 | throw Exception(ErrorCodes::CANNOT_PARSE_YAML, |
| 172 | "YAMLParser has encountered node with key " |
| 173 | "or value which cannot be represented as string and cannot continue parsing of the file"); |
| 174 | } |
| 175 | return xml; |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | #else |