From 17e15033e1f4f682866c446855fefe8a7e2913a0 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Wed, 7 Dec 2016 11:42:13 -0800 Subject: [PATCH] Log helpful error message if mmap fails. --- CHANGELOG.md | 1 + features/options/contract/invalid.feature | 16 ++++++++++++++++ src/contractor/contractor.cpp | 16 ++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6be4a47..31fcc41b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - fixed a bug that could result in inconsistent behaviour when collapsing instructions - fixed a bug that could result in crashes when leaving a ferry directly onto a motorway ramp - fixed a bug in the tile plugin that resulted in discovering invalid edges for connections + - improved error messages when missing files during traffic updates (#3114) - Debug Tiles - Added support for turn penalties - Internals diff --git a/features/options/contract/invalid.feature b/features/options/contract/invalid.feature index 127761ee3..b4413f111 100644 --- a/features/options/contract/invalid.feature +++ b/features/options/contract/invalid.feature @@ -3,6 +3,14 @@ Feature: osrm-contract command line options: invalid options Background: Given the profile "testbot" + And the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been extracted Scenario: osrm-contract - Non-existing option When I try to run "osrm-contract --fly-me-to-the-moon" @@ -10,3 +18,11 @@ Feature: osrm-contract command line options: invalid options And stderr should contain "option" And stderr should contain "fly-me-to-the-moon" And it should exit with an error + + # This tests the error messages when you try to use --segment-speed-file, + # but osrm-extract has not been run with --generate-edge-lookup + Scenario: osrm-contract - Someone forgot --generate-edge-lookup on osrm-extract + When I try to run "osrm-contract --segment-speed-file /dev/null {processed_file}" + Then stderr should contain "Error while trying to mmap" + Then stderr should contain ".osrm.edge_penalties" + And it should exit with an error diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index 80f74b680..55b8fcbbb 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -521,10 +521,18 @@ EdgeID Contractor::LoadEdgeExpandedGraph( using boost::interprocess::mapped_region; using boost::interprocess::read_only; - const file_mapping mapping{filename.c_str(), read_only}; - mapped_region region{mapping, read_only}; - region.advise(mapped_region::advice_sequential); - return region; + try + { + const file_mapping mapping{filename.c_str(), read_only}; + mapped_region region{mapping, read_only}; + region.advise(mapped_region::advice_sequential); + return region; + } + catch (const std::exception &e) + { + util::Log(logERROR) << "Error while trying to mmap " + filename + ": " + e.what(); + throw; + } }; const auto edge_based_graph_region = mmap_file(edge_based_graph_filename);