ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

error.ha (2021B)


      1 use encoding::utf8;
      2 use fmt;
      3 use fs;
      4 use io;
      5 use os;
      6 use os::exec;
      7 use regex;
      8 
      9 type Error = !(...InteractionError | ...ParseError | ...CmdError);
     10 
     11 fn errormsg(s: *Session, err: Error) void = {
     12 	if (err is Quit)
     13 		return;
     14 
     15 	fmt::errorln('?')!;
     16 	if (s.helpmode)
     17 		fmt::errorfln(strerror(err))!;
     18 
     19 	s.lasterror = err;
     20 };
     21 
     22 fn strerror(err: Error) str = {
     23 	match (err) {
     24 	// InteractionError
     25 	case let e: InteractionError =>
     26 		match (e) {
     27 		case Quit =>
     28 			return "";
     29 		case UnexpectedEOF =>
     30 			return "Unexpected end-of-file input";
     31 		case let e: encoding::utf8::invalid =>
     32 			return encoding::utf8::strerror(e);
     33 		case let e: io::error =>
     34 			return io::strerror(e);
     35 		};
     36 	// CmdError
     37 	case InvalidAddress =>
     38 		return "Invalid address";
     39 	case NoFilename =>
     40 		return "No filename";
     41 	case WarnBufferModified =>
     42 		return "Warning: Buffer modified";
     43 	case UnexpectedAddress =>
     44 		return "Unexpected address";
     45 	case InvalidDestination =>
     46 		return "Invalid destination";
     47 	case NoMatch =>
     48 		return "No match";
     49 	case NoPrevRegex =>
     50 		return "No previous search pattern";
     51 	case NoPrevShCmd =>
     52 		return "No previous shell command";
     53 	case NoPrevGlobalSubCmd =>
     54 		return "No previous global subcommand";
     55 	case let e: InvalidGlobalSubCmd =>
     56 		return "Invalid interactive global subcommand"; // TODO: append 'e'?
     57 	case NoHistory =>
     58 		return "Nothing to undo"; // TODO: append 'e'?
     59 	case let e: regex::error =>
     60 		return regex::strerror(e);
     61 	case let e: fs::error =>
     62 		return fs::strerror(e);
     63 	case let e: os::exec::error =>
     64 		return os::exec::strerror(e);
     65 	// ParseError
     66 	case let e: UnknownCommand =>
     67 		return "Unknown command"; // TODO: append 'e'?
     68 	case InvalidSuffix =>
     69 		return "Invalid suffix";
     70 	case UnexpectedSuffix =>
     71 		return "Unexpected suffix";
     72 	case TrailingCharacters =>
     73 		return "Trailing characters";
     74 	case ExpectedArgument =>
     75 		return "Expected argument";
     76 	case ExpectedMark =>
     77 		return "Expected mark";
     78 	case InvalidDelimiter =>
     79 		return "Invalid delimiter";
     80 	case ExpectedDelimiter =>
     81 		return "Expected delimiter";
     82 	};
     83 };