Mercurial > hg > octave-nkf
changeset 17996:260b44c0ed69
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 24 Nov 2013 14:23:20 -0500 |
parents | ea1db0ede4ce |
children | 8dd427538147 |
files | liboctave/util/cmd-hist.cc liboctave/util/cmd-hist.h |
diffstat | 2 files changed, 30 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/cmd-hist.cc +++ b/liboctave/util/cmd-hist.cc @@ -27,6 +27,7 @@ #include <cstring> #include <iostream> +#include <sstream> #include <string> #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