diff --git a/src/bind/syscmd/source.cpp b/src/bind/syscmd/source.cpp index 3fecee5c..9de3f49f 100644 --- a/src/bind/syscmd/source.cpp +++ b/src/bind/syscmd/source.cpp @@ -120,7 +120,7 @@ namespace return text ; } - std::error_code do_runcommand( + void do_runcommand( const std::string& cmd, const std::string& args, const std::filesystem::path& parent_path, @@ -131,26 +131,26 @@ namespace switch(rcindex) { case RunCommandsIndex::SET: { Set::sprocess(1, cmd + " " + args) ; - return std::error_code() ; + return ; } case RunCommandsIndex::COMMAND: { Command::sprocess(1, cmd + " " + args, as_default) ; - return std::error_code() ; + return ; } case RunCommandsIndex::DELCOMMAND: { Delcommand::sprocess(1, cmd + " " + args, as_default) ; - return std::error_code() ; + return ; } case RunCommandsIndex::COMCLEAR: { if(!args.empty()) { - return std::make_error_code(std::errc::invalid_argument) ; + throw std::make_error_code(std::errc::invalid_argument) ; } Comclear::sprocess(1, "", as_default) ; - return std::error_code() ; + return ; } case RunCommandsIndex::SOURCE: { if(args.empty()) { - return std::make_error_code(std::errc::invalid_argument) ; + throw std::make_error_code(std::errc::invalid_argument) ; } auto path = \ @@ -158,7 +158,7 @@ namespace if(std::filesystem::exists(path)) { if(std::filesystem::equivalent(core::RC(), path)) { - return std::make_error_code(std::errc::text_file_busy) ; + throw std::make_error_code(std::errc::text_file_busy) ; } Source::sprocess(1, cmd + " " + path.u8string(), as_default) ; } @@ -166,7 +166,7 @@ namespace Source::sprocess(1, cmd + " " + load_remote_vindrc(args).u8string()) ; } - return std::error_code() ; + return ; } default: { break ; @@ -188,15 +188,14 @@ namespace } else if(util::enum_has_bits(rcindex, RunCommandsIndex::MASK_MAPCLEAR)) { if(!args.empty()) { - return std::make_error_code(std::errc::invalid_argument) ; + throw std::make_error_code(std::errc::invalid_argument) ; } auto [prefix, _] = core::divide_prefix_and_cmd(cmd, "m") ; do_mapclear(prefix, as_default) ; } else { - return std::make_error_code(std::errc::argument_out_of_domain) ; + throw std::make_error_code(std::errc::argument_out_of_domain) ; } - return std::error_code() ; } void init_default_mapping(const std::string& tier="huge") { @@ -270,8 +269,11 @@ namespace vind continue ; } - if(auto err = do_runcommand(cmd, line_args, path.parent_path(), as_default)) { - auto ltag = "L:" + std::to_string(lnum) ; + auto ltag = "L:" + std::to_string(lnum) ; + try { + do_runcommand(cmd, line_args, path.parent_path(), as_default) ; + } + catch(const std::error_code& err) { std::stringstream cmdline_ss ; std::stringstream log_ss ; @@ -291,13 +293,20 @@ namespace vind cmdline_ss << " (" << ltag << ")" ; opt::VCmdLine::print(opt::ErrorMessage(cmdline_ss.str())) ; - log_ss << " (" << path.u8string() << ", " << ltag << ") " ; - PRINT_ERROR(log_ss.str()) ; + log_ss << " (" << path.u8string() << ", " << ltag << ")" ; + core::Logger::get_instance().error(log_ss.str()) ; core::InputHub::get_instance().clear_mapping( core::Mode::UNDEFINED, as_default) ; break ; } + catch(const std::runtime_error& e) { + std::stringstream log_ss ; + log_ss << cmd << ": " << e.what() ; + log_ss << " (" << path.u8string() << ", " << ltag << ")" ; + core::Logger::get_instance().error(log_ss.str()) ; + continue ; + } } // If the .vindrc is empty, apply a default tier. diff --git a/src/core/errlogger.cpp b/src/core/errlogger.cpp index d72c8a71..6fa64250 100644 --- a/src/core/errlogger.cpp +++ b/src/core/errlogger.cpp @@ -194,8 +194,9 @@ namespace vind if(size > 0) { LocalFree(msgbuf) ; } + + pimpl->stream_ << std::endl ; } - pimpl->stream_ << std::endl ; pimpl->stream_ << "[Error] " << msg ; if(!scope.empty()) { diff --git a/src/core/keycode.cpp b/src/core/keycode.cpp index f290bd4f..6b2a0d35 100644 --- a/src/core/keycode.cpp +++ b/src/core/keycode.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -484,7 +485,10 @@ namespace vind auto keycode = static_cast(res & 0x00ff) ; if(keycode == 0xff) { - return KeyCode{} ; + std::stringstream ss ; + ss << "The specified letter `" << ascii << "`" ; + ss << " cannot be typed directly in your keyboard layout." ; + throw std::runtime_error(ss.str()) ; } return KeyCode{keycode} ;