Skip to content

Commit

Permalink
Improved JSON parsing error reporting, see #147
Browse files Browse the repository at this point in the history
  • Loading branch information
bondagit committed Jan 21, 2024
1 parent 67a3b0a commit 2cad593
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions daemon/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,12 @@ Config json_to_config_(std::istream& js, Config& config) {
} catch (boost::property_tree::json_parser::json_parser_error& je) {
throw std::runtime_error("error parsing JSON at line " +
std::to_string(je.line()) + " :" + je.message());
} catch (...) {
throw std::runtime_error("failed to convert a number");
} catch (std::invalid_argument& e) {
throw std::runtime_error("error parsing JSON: cannot perform number conversion");
} catch (std::out_of_range& e) {
throw std::runtime_error("error parsing JSON: number conversion out of range");
} catch (std::exception& e) {
throw std::runtime_error("error parsing JSON: " + std::string(e.what()));
}
return config;
}
Expand Down Expand Up @@ -412,8 +416,12 @@ StreamSource json_to_source(const std::string& id, const std::string& json) {
} catch (boost::property_tree::json_parser::json_parser_error& je) {
throw std::runtime_error("error parsing JSON at line " +
std::to_string(je.line()) + " :" + je.message());
} catch (...) {
throw std::runtime_error("failed to convert a number");
} catch (std::invalid_argument& e) {
throw std::runtime_error("error parsing JSON: cannot perform number conversion");
} catch (std::out_of_range& e) {
throw std::runtime_error("error parsing JSON: number conversion out of range");
} catch (std::exception& e) {
throw std::runtime_error("error parsing JSON: " + std::string(e.what()));
}
return source;
}
Expand Down Expand Up @@ -452,8 +460,12 @@ StreamSink json_to_sink(const std::string& id, const std::string& json) {
} catch (boost::property_tree::json_parser::json_parser_error& je) {
throw std::runtime_error("error parsing JSON at line " +
std::to_string(je.line()) + " :" + je.message());
} catch (...) {
throw std::runtime_error("failed to convert a number");
} catch (std::invalid_argument& e) {
throw std::runtime_error("error parsing JSON: cannot perform number conversion");
} catch (std::out_of_range& e) {
throw std::runtime_error("error parsing JSON: number conversion out of range");
} catch (std::exception& e) {
throw std::runtime_error("error parsing JSON: " + std::string(e.what()));
}
return sink;
}
Expand Down

0 comments on commit 2cad593

Please sign in to comment.