[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 14d582d 7/7: Trap exceptions from filesystem
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 14d582d 7/7: Trap exceptions from filesystem library |
Date: |
Wed, 7 Oct 2020 19:36:14 -0400 (EDT) |
branch: master
commit 14d582d499d7487ba10e81d9f2213d876b102d78
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Trap exceptions from filesystem library
Prevent this problem:
$wine ./lmi_wx_shared --ash_nazg --data_path=/opt/lmi/data
boost::filesystem::path: invalid name "Z:" in path: \
"/opt/lmi/src/lmi/Z:/etc/opt/lmi/default.ill"
Alarum: Instantiation failed.
[configurable_settings.cpp : 193]
(terminates with nonzero return code)
Instead, show the filesystem error in a messagebox, and let the end user
dismiss it and continue normally.
Further refinements are certainly possible, but a forcible exit with no
workaround had to be prevented now. It seems better to wait until the
boost library is replaced by std::filesystem before any further change.
One obvious alternative is to store a generic path and convert to the
"native" form, internally, for actual use.
---
configurable_settings.cpp | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/configurable_settings.cpp b/configurable_settings.cpp
index 8316b05..288284a 100644
--- a/configurable_settings.cpp
+++ b/configurable_settings.cpp
@@ -146,11 +146,25 @@ configurable_settings::configurable_settings()
ascribe_members();
load();
- default_input_filename_ =
fs::system_complete(default_input_filename_).string();
- print_directory_ = fs::system_complete(print_directory_
).string();
+ try
+ {
+ default_input_filename_ =
fs::system_complete(default_input_filename_).string();
+// Performing this test seems like a good idea, but it would flag
+// an empty path as an error.
+// validate_filepath(default_input_filename_, "Default input file");
+ }
+ catch(...)
+ {
+ report_exception();
+ // Silently replace invalid path with an empty string,
+ // which will produce an informative diagnostic when
+ // a default is needed.
+ default_input_filename_ = {};
+ }
try
{
+ print_directory_ = fs::system_complete(print_directory_).string();
validate_directory(print_directory_, "Print directory");
}
catch(...)
- [lmi-commits] [lmi] master updated (61f5559 -> 14d582d), Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master ff1dd28 1/7: Improve measurement of compound-interest performance, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 7846a21 2/7: Fix defect introduced 20201004T1606Z: typo in variable name, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master b8061ca 3/7: Treat gcc versions "10" and "10.0" as the same, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 9a6cab4 4/7: Treat gcc versions "[89]" and "[89]\.*" as the same, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 81e3462 5/7: Specify a default data directory for CGI, Greg Chicares, 2020/10/07
- [lmi-commits] [lmi] master 14d582d 7/7: Trap exceptions from filesystem library,
Greg Chicares <=
- [lmi-commits] [lmi] master c85b44f 6/7: Force print directory more sensibly, Greg Chicares, 2020/10/07