# HG changeset patch # User John W. Eaton # Date 1385321000 18000 # Node ID 260b44c0ed690b8d8fe678e3b62124917228fd32 # Parent ea1db0ede4ce0a0ddcb628dc28e4af00784c4a21 improve messages when reading or writing history fails (bug #40443) * cmd-hist.h, cmd-hist.cc (command_history::error): New arg, MSG. If MSG is not empty, use it as a prefix for the strerror message. (gnu_history::do_read, gnu_history::do_read_range, gnu_history::do_write, gnu_history::do_append): Call error with additional message. diff -r ea1db0ede4ce -r 260b44c0ed69 liboctave/util/cmd-hist.cc --- a/liboctave/util/cmd-hist.cc Sun Nov 24 13:11:36 2013 +0100 +++ b/liboctave/util/cmd-hist.cc Sun Nov 24 14:23:20 2013 -0500 @@ -27,6 +27,7 @@ #include #include +#include #include #include "cmd-edit.h" @@ -302,7 +303,11 @@ int status = ::octave_read_history (f.c_str ()); if (status != 0 && must_exist) - error (status); + { + std::string msg = "reading file '" + f + "'"; + + error (status, msg); + } else { lines_in_file = do_where (); @@ -326,7 +331,13 @@ int status = ::octave_read_history_range (f.c_str (), from, to); if (status != 0 && must_exist) - error (status); + { + std::ostringstream buf; + buf << "reading lines " << from << " to " << to + << " from file '" << f << "'"; + + error (status, buf.str ()); + } else { lines_in_file = do_where (); @@ -353,7 +364,11 @@ int status = ::octave_write_history (f.c_str ()); if (status != 0) - error (status); + { + std::string msg = "writing file '" + f + "'"; + + error (status, msg); + } } else error ("gnu_history::write: missing file name"); @@ -392,7 +407,11 @@ = ::octave_append_history (lines_this_session, f.c_str ()); if (status != 0) - error (status); + { + std::string msg = "appending to file '" + f_arg + "'"; + + error (status, msg); + } else lines_in_file += lines_this_session; @@ -995,9 +1014,13 @@ } void -command_history::error (int err_num) const +command_history::error (int err_num, const std::string& msg) const { - (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); + if (msg.empty ()) + (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); + else + (*current_liboctave_error_handler) ("%s: %s", msg.c_str (), + gnulib::strerror (err_num)); } void diff -r ea1db0ede4ce -r 260b44c0ed69 liboctave/util/cmd-hist.h --- a/liboctave/util/cmd-hist.h Sun Nov 24 13:11:36 2013 +0100 +++ b/liboctave/util/cmd-hist.h Sun Nov 24 14:23:20 2013 -0500 @@ -201,7 +201,7 @@ virtual void do_clean_up_and_save (const std::string&, int); - void error (int) const; + void error (int, const std::string& msg = "") const; void error (const std::string&) const;