1use oxdock_diagnostics::Diagnostic;
12use oxdock_parser::{HANDLE_TYPE_NAME, KEYWORD_ASYNC, KEYWORD_LET};
13
14const FIELD_FUNC: &str = "func";
18const FIELD_WORKER: &str = "worker";
19const FIELD_NAME: &str = "name";
20const FIELD_RAW: &str = "raw";
21const FIELD_PATH: &str = "path";
22const FIELD_ALGORITHM: &str = "algorithm";
23const FIELD_MODE: &str = "mode";
24const FIELD_ERR: &str = "err";
25const FIELD_CODE: &str = "code";
26const FIELD_OPTION: &str = "option";
27const FIELD_GOT: &str = "got";
28
29pub fn key_path_escapes(func: &str, raw: &str) -> Diagnostic {
32 let message = format!("{func} key_path escapes the workspace: {raw}");
33 Diagnostic::new(
34 "ssh.key.escapes_workspace",
35 message,
36 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_RAW, raw)]),
37 )
38}
39
40pub fn host_key_must_be_ed25519(
44 func: &str,
45 path: &str,
46 algorithm: &impl std::fmt::Debug,
47) -> Diagnostic {
48 let algorithm_text = format!("{algorithm:?}");
49 let message = format!("{func} host key {path} must be Ed25519, found {algorithm_text}");
50 Diagnostic::new(
51 "ssh.key.must_be_ed25519",
52 message,
53 Diagnostic::make_fields(&[
54 (FIELD_FUNC, func),
55 (FIELD_PATH, path),
56 (FIELD_ALGORITHM, algorithm_text.as_str()),
57 ]),
58 )
59}
60
61pub fn host_key_insecure_permissions(func: &str, path: &str, mode: u32) -> Diagnostic {
65 let mode_text = format!("0{mode:o}");
66 let message = format!(
67 "{func} insecure permissions on host key file {path}: expected 0600, got {mode_text}"
68 );
69 Diagnostic::new(
70 "ssh.key.insecure_permissions",
71 message,
72 Diagnostic::make_fields(&[
73 (FIELD_FUNC, func),
74 (FIELD_PATH, path),
75 (FIELD_MODE, mode_text.as_str()),
76 ]),
77 )
78}
79
80pub fn host_key_resolver_failed(func: &str, reason: &anyhow::Error) -> Diagnostic {
86 let reason_text = format!("{reason:#}");
87 Diagnostic::new(
88 "ssh.key.resolver_failed",
89 format!("{func} cannot open the workspace resolver"),
90 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, &reason_text)]),
91 )
92 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
93}
94
95pub fn host_key_generate_failed(
99 reason: impl std::error::Error + Send + Sync + 'static,
100) -> Diagnostic {
101 let reason_text = reason.to_string();
102 Diagnostic::new(
103 "ssh.key.generate_failed",
104 "generate Ed25519 host key".to_string(),
105 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
106 )
107 .with_source(std::sync::Arc::new(reason))
108}
109
110pub fn host_key_encode_failed(
113 reason: impl std::error::Error + Send + Sync + 'static,
114) -> Diagnostic {
115 let reason_text = reason.to_string();
116 Diagnostic::new(
117 "ssh.key.encode_failed",
118 "encode Ed25519 host key".to_string(),
119 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
120 )
121 .with_source(std::sync::Arc::new(reason))
122}
123
124pub fn key_guard_failed(func: &str, reason: &anyhow::Error) -> Diagnostic {
128 let reason_text = format!("{reason:#}");
129 Diagnostic::new(
130 "ssh.key.guard_failed",
131 format!("{func} cannot guard the workspace root"),
132 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, &reason_text)]),
133 )
134 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
135}
136
137pub fn host_key_stat_failed(path: &str, reason: &anyhow::Error) -> Diagnostic {
141 let reason_text = format!("{reason:#}");
142 Diagnostic::new(
143 "ssh.key.stat_failed",
144 format!("cannot stat host key {path}"),
145 Diagnostic::make_fields(&[(FIELD_PATH, path), (FIELD_ERR, &reason_text)]),
146 )
147 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
148}
149
150pub fn host_key_read_failed(func: &str, path: &str, reason: &anyhow::Error) -> Diagnostic {
154 let reason_text = format!("{reason:#}");
155 Diagnostic::new(
156 "ssh.key.read_failed",
157 format!("{func} cannot read host key {path}"),
158 Diagnostic::make_fields(&[
159 (FIELD_FUNC, func),
160 (FIELD_PATH, path),
161 (FIELD_ERR, &reason_text),
162 ]),
163 )
164 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
165}
166
167pub fn host_key_parse_failed(
171 func: &str,
172 path: &str,
173 reason: impl std::error::Error + Send + Sync + 'static,
174) -> Diagnostic {
175 let reason_text = reason.to_string();
176 Diagnostic::new(
177 "ssh.key.parse_failed",
178 format!("{func} cannot parse host key {path}"),
179 Diagnostic::make_fields(&[
180 (FIELD_FUNC, func),
181 (FIELD_PATH, path),
182 (FIELD_ERR, &reason_text),
183 ]),
184 )
185 .with_source(std::sync::Arc::new(reason))
186}
187
188pub fn host_key_write_failed(reason: &anyhow::Error) -> Diagnostic {
192 let reason_text = format!("{reason:#}");
193 Diagnostic::new(
194 "ssh.key.write_failed",
195 reason_text.clone(),
196 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
197 )
198}
199
200pub fn key_path_join_failed(func: &str, raw: &str, reason: &anyhow::Error) -> Diagnostic {
205 let reason_text = format!("{reason:#}");
206 Diagnostic::new(
207 "ssh.key.join_failed",
208 format!("{func} key_path escapes the workspace: {raw}"),
209 Diagnostic::make_fields(&[
210 (FIELD_FUNC, func),
211 (FIELD_RAW, raw),
212 (FIELD_ERR, &reason_text),
213 ]),
214 )
215 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
216}
217
218pub fn pump_output_lock_poisoned() -> Diagnostic {
221 Diagnostic::new(
222 "ssh.pump.output_lock_poisoned",
223 "SSH pump output lock poisoned".to_string(),
224 Diagnostic::make_fields(&[]),
225 )
226}
227
228pub fn pump_input_read_failed(err: &std::io::Error) -> Diagnostic {
231 let err_text = err.to_string();
232 let message = format!("SSH pump input pipe read failed: {err_text}");
233 Diagnostic::new(
234 "ssh.pump.input_read_failed",
235 message,
236 Diagnostic::make_fields(&[(FIELD_ERR, err_text.as_str())]),
237 )
238}
239
240pub fn pump_worker_panicked(worker: &str) -> Diagnostic {
243 let message = format!("SSH pump {worker} panicked");
244 Diagnostic::new(
245 "ssh.pump.worker_panicked",
246 message,
247 Diagnostic::make_fields(&[(FIELD_WORKER, worker)]),
248 )
249}
250
251pub fn pump_interrupted_by_cancellation() -> Diagnostic {
254 Diagnostic::new(
255 "ssh.pump.interrupted_by_cancellation",
256 "SSH pump interrupted by cancellation".to_string(),
257 Diagnostic::make_fields(&[]),
258 )
259}
260
261pub fn pump_source_read_failed(err: &std::io::Error) -> Diagnostic {
264 let err_text = err.to_string();
265 let message = format!("SSH_PUMP source pipe read failed: {err_text}");
266 Diagnostic::new(
267 "ssh.pump.source_read_failed",
268 message,
269 Diagnostic::make_fields(&[(FIELD_ERR, err_text.as_str())]),
270 )
271}
272
273pub fn pump_target_lock_poisoned() -> Diagnostic {
276 Diagnostic::new(
277 "ssh.pump.target_lock_poisoned",
278 "SSH_PUMP target lock poisoned".to_string(),
279 Diagnostic::make_fields(&[]),
280 )
281}
282
283pub fn pump_func_input_read_failed(func: &str, err: &std::io::Error) -> Diagnostic {
286 let err_text = err.to_string();
287 let message = format!("{func} input pipe read failed: {err_text}");
288 Diagnostic::new(
289 "ssh.pump.func_input_read_failed",
290 message,
291 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, err_text.as_str())]),
292 )
293}
294
295pub fn pump_output_write_failed(
299 reason: impl std::error::Error + Send + Sync + 'static,
300) -> Diagnostic {
301 let reason_text = reason.to_string();
302 Diagnostic::new(
303 "ssh.pump.output_write_failed",
304 "SSH pump output pipe write failed".to_string(),
305 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
306 )
307 .with_source(std::sync::Arc::new(reason))
308}
309
310pub fn pump_output_flush_failed(
313 reason: impl std::error::Error + Send + Sync + 'static,
314) -> Diagnostic {
315 let reason_text = reason.to_string();
316 Diagnostic::new(
317 "ssh.pump.output_flush_failed",
318 "SSH pump output pipe flush failed".to_string(),
319 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
320 )
321 .with_source(std::sync::Arc::new(reason))
322}
323
324pub fn pump_borrow_input_failed(reason: Diagnostic) -> Diagnostic {
328 let reason_text = reason.to_string();
329 Diagnostic::new(
330 "ssh.pump.borrow_input_failed",
331 "SSH pump cannot borrow the input pipe".to_string(),
332 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
333 )
334 .with_source(std::sync::Arc::new(reason))
335}
336
337pub fn pump_borrow_output_failed(reason: Diagnostic) -> Diagnostic {
340 let reason_text = reason.to_string();
341 Diagnostic::new(
342 "ssh.pump.borrow_output_failed",
343 "SSH pump cannot borrow the output pipe".to_string(),
344 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
345 )
346 .with_source(std::sync::Arc::new(reason))
347}
348
349pub fn pump_wait_runtime_failed(
352 reason: impl std::error::Error + Send + Sync + 'static,
353) -> Diagnostic {
354 let reason_text = reason.to_string();
355 Diagnostic::new(
356 "ssh.pump.wait_runtime_failed",
357 "SSH pump wait runtime failed".to_string(),
358 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
359 )
360 .with_source(std::sync::Arc::new(reason))
361}
362
363pub fn pump_borrow_source_failed(reason: Diagnostic) -> Diagnostic {
366 let reason_text = reason.to_string();
367 Diagnostic::new(
368 "ssh.pump.borrow_source_failed",
369 "SSH_PUMP cannot borrow the source pipe".to_string(),
370 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
371 )
372 .with_source(std::sync::Arc::new(reason))
373}
374
375pub fn pump_borrow_target_failed(reason: Diagnostic) -> Diagnostic {
378 let reason_text = reason.to_string();
379 Diagnostic::new(
380 "ssh.pump.borrow_target_failed",
381 "SSH_PUMP cannot borrow the target pipe".to_string(),
382 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
383 )
384 .with_source(std::sync::Arc::new(reason))
385}
386
387pub fn pump_target_write_failed(
390 reason: impl std::error::Error + Send + Sync + 'static,
391) -> Diagnostic {
392 let reason_text = reason.to_string();
393 Diagnostic::new(
394 "ssh.pump.target_write_failed",
395 "SSH_PUMP target pipe write failed".to_string(),
396 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
397 )
398 .with_source(std::sync::Arc::new(reason))
399}
400
401pub fn pump_target_flush_failed(
404 reason: impl std::error::Error + Send + Sync + 'static,
405) -> Diagnostic {
406 let reason_text = reason.to_string();
407 Diagnostic::new(
408 "ssh.pump.target_flush_failed",
409 "SSH_PUMP target pipe flush failed".to_string(),
410 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
411 )
412 .with_source(std::sync::Arc::new(reason))
413}
414
415pub fn authentication_rejected(func: &str) -> Diagnostic {
419 let message = format!("{func} authentication rejected");
420 Diagnostic::new(
421 "ssh.auth.rejected",
422 message,
423 Diagnostic::make_fields(&[(FIELD_FUNC, func)]),
424 )
425}
426
427pub fn dial_failed(func: &str, reason: &anyhow::Error) -> Diagnostic {
433 let reason_text = format!("{reason:#}");
434 Diagnostic::new(
435 "ssh.dial_failed",
436 format!("{func} dial failed"),
437 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, &reason_text)]),
438 )
439 .with_source(std::sync::Arc::new(std::io::Error::other(reason_text)))
440}
441
442pub fn auth_exchange_failed(
446 func: &str,
447 reason: impl std::error::Error + Send + Sync + 'static,
448) -> Diagnostic {
449 let reason_text = reason.to_string();
450 Diagnostic::new(
451 "ssh.auth.exchange_failed",
452 format!("{func} authentication exchange failed"),
453 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, &reason_text)]),
454 )
455 .with_source(std::sync::Arc::new(reason))
456}
457
458pub fn channel_open_failed(
462 func: &str,
463 reason: impl std::error::Error + Send + Sync + 'static,
464) -> Diagnostic {
465 let reason_text = reason.to_string();
466 Diagnostic::new(
467 "ssh.channel.open_failed",
468 format!("{func} channel open failed"),
469 Diagnostic::make_fields(&[(FIELD_FUNC, func), (FIELD_ERR, &reason_text)]),
470 )
471 .with_source(std::sync::Arc::new(reason))
472}
473
474pub fn exec_request_failed(reason: impl std::error::Error + Send + Sync + 'static) -> Diagnostic {
477 let reason_text = reason.to_string();
478 Diagnostic::new(
479 "ssh.exec.request_failed",
480 "SSH_EXEC exec request failed".to_string(),
481 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
482 )
483 .with_source(std::sync::Arc::new(reason))
484}
485
486pub fn shell_request_failed(reason: impl std::error::Error + Send + Sync + 'static) -> Diagnostic {
489 let reason_text = reason.to_string();
490 Diagnostic::new(
491 "ssh.connect.shell_request_failed",
492 "SSH_CONNECT shell request failed".to_string(),
493 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
494 )
495 .with_source(std::sync::Arc::new(reason))
496}
497
498pub fn listener_prepare_failed(
502 reason: impl std::error::Error + Send + Sync + 'static,
503) -> Diagnostic {
504 let reason_text = reason.to_string();
505 Diagnostic::new(
506 "ssh.serve.listener_prepare_failed",
507 "prepare listener for the runtime".to_string(),
508 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
509 )
510 .with_source(std::sync::Arc::new(reason))
511}
512
513pub fn listener_handoff_failed(
516 reason: impl std::error::Error + Send + Sync + 'static,
517) -> Diagnostic {
518 let reason_text = reason.to_string();
519 Diagnostic::new(
520 "ssh.serve.listener_handoff_failed",
521 "hand listener to the runtime".to_string(),
522 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
523 )
524 .with_source(std::sync::Arc::new(reason))
525}
526
527pub fn listener_failed(reason: impl std::error::Error + Send + Sync + 'static) -> Diagnostic {
530 let reason_text = reason.to_string();
531 Diagnostic::new(
532 "ssh.serve.listener_failed",
533 "SSH listener failed".to_string(),
534 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
535 )
536 .with_source(std::sync::Arc::new(reason))
537}
538
539pub fn client_runtime_build_failed(
542 reason: impl std::error::Error + Send + Sync + 'static,
543) -> Diagnostic {
544 let reason_text = reason.to_string();
545 Diagnostic::new(
546 "ssh.client_runtime.build_failed",
547 "build SSH client runtime".to_string(),
548 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
549 )
550 .with_source(std::sync::Arc::new(reason))
551}
552
553pub fn session_pump_already_finished() -> Diagnostic {
556 Diagnostic::new(
557 "ssh.session.pump_already_finished",
558 "SSH session pump already finished".to_string(),
559 Diagnostic::make_fields(&[]),
560 )
561}
562
563pub fn session_wire_queue_saturated() -> Diagnostic {
566 Diagnostic::new(
567 "ssh.session.wire_queue_saturated",
568 "SSH session wire queue saturated under backpressure".to_string(),
569 Diagnostic::make_fields(&[]),
570 )
571}
572
573pub fn session_wire_writer_gone() -> Diagnostic {
576 Diagnostic::new(
577 "ssh.session.wire_writer_gone",
578 "SSH session wire writer is gone".to_string(),
579 Diagnostic::make_fields(&[]),
580 )
581}
582
583pub fn session_already_pumped() -> Diagnostic {
586 Diagnostic::new(
587 "ssh.session.already_pumped",
588 "SSH session already pumped".to_string(),
589 Diagnostic::make_fields(&[]),
590 )
591}
592
593pub fn channel_data_unknown() -> Diagnostic {
596 Diagnostic::new(
597 "ssh.channel.data_unknown",
598 "data for unknown channel".to_string(),
599 Diagnostic::make_fields(&[]),
600 )
601}
602
603pub fn channel_pump_gone() -> Diagnostic {
605 Diagnostic::new(
606 "ssh.channel.pump_gone",
607 "pump went away".to_string(),
608 Diagnostic::make_fields(&[]),
609 )
610}
611
612pub fn channel_wire_gone_eof_close() -> Diagnostic {
615 Diagnostic::new(
616 "ssh.channel.wire_gone_eof_close",
617 "wire gone during EOF close".to_string(),
618 Diagnostic::make_fields(&[]),
619 )
620}
621
622pub fn channel_request_unknown() -> Diagnostic {
625 Diagnostic::new(
626 "ssh.channel.request_unknown",
627 "request for unknown channel".to_string(),
628 Diagnostic::make_fields(&[]),
629 )
630}
631
632pub fn channel_already_announced() -> Diagnostic {
634 Diagnostic::new(
635 "ssh.channel.already_announced",
636 "channel already announced".to_string(),
637 Diagnostic::make_fields(&[]),
638 )
639}
640
641pub fn run_child_read_failed(name: &str, err: &std::io::Error) -> Diagnostic {
644 let err_text = err.to_string();
645 let message = format!("SSH run child {name} read failed: {err_text}");
646 Diagnostic::new(
647 "ssh.run.child_read_failed",
648 message,
649 Diagnostic::make_fields(&[(FIELD_NAME, name), (FIELD_ERR, err_text.as_str())]),
650 )
651}
652
653pub fn run_output_write_failed(
656 reason: impl std::error::Error + Send + Sync + 'static,
657) -> Diagnostic {
658 let reason_text = reason.to_string();
659 Diagnostic::new(
660 "ssh.run.output_write_failed",
661 "SSH run output pipe write failed".to_string(),
662 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
663 )
664 .with_source(std::sync::Arc::new(reason))
665}
666
667pub fn run_output_flush_failed(
670 reason: impl std::error::Error + Send + Sync + 'static,
671) -> Diagnostic {
672 let reason_text = reason.to_string();
673 Diagnostic::new(
674 "ssh.run.output_flush_failed",
675 "SSH run output pipe flush failed".to_string(),
676 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
677 )
678 .with_source(std::sync::Arc::new(reason))
679}
680
681pub fn run_output_lock_poisoned() -> Diagnostic {
684 Diagnostic::new(
685 "ssh.run.output_lock_poisoned",
686 "SSH run output lock poisoned".to_string(),
687 Diagnostic::make_fields(&[]),
688 )
689}
690
691pub fn run_needs_program() -> Diagnostic {
693 Diagnostic::new(
694 "ssh.run.needs_program",
695 "SSH_RUN needs at least a program".to_string(),
696 Diagnostic::make_fields(&[]),
697 )
698}
699
700pub fn run_spawn_lost_stderr() -> Diagnostic {
703 Diagnostic::new(
704 "ssh.run.spawn_lost_stderr",
705 "SSH run spawn lost stderr".to_string(),
706 Diagnostic::make_fields(&[]),
707 )
708}
709
710pub fn run_interrupted_by_cancellation() -> Diagnostic {
713 Diagnostic::new(
714 "ssh.run.interrupted_by_cancellation",
715 "SSH run interrupted by cancellation".to_string(),
716 Diagnostic::make_fields(&[]),
717 )
718}
719
720pub fn run_borrow_input_failed(reason: Diagnostic) -> Diagnostic {
723 let reason_text = reason.to_string();
724 Diagnostic::new(
725 "ssh.run.borrow_input_failed",
726 "SSH run cannot borrow the input pipe".to_string(),
727 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
728 )
729 .with_source(std::sync::Arc::new(reason))
730}
731
732pub fn run_borrow_output_failed(reason: Diagnostic) -> Diagnostic {
735 let reason_text = reason.to_string();
736 Diagnostic::new(
737 "ssh.run.borrow_output_failed",
738 "SSH run cannot borrow the output pipe".to_string(),
739 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
740 )
741 .with_source(std::sync::Arc::new(reason))
742}
743
744pub fn run_borrow_error_failed(reason: Diagnostic) -> Diagnostic {
747 let reason_text = reason.to_string();
748 Diagnostic::new(
749 "ssh.run.borrow_error_failed",
750 "SSH run cannot borrow the error pipe".to_string(),
751 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
752 )
753 .with_source(std::sync::Arc::new(reason))
754}
755
756pub fn run_spawn_failed(reason: Diagnostic) -> Diagnostic {
759 let reason_text = reason.to_string();
760 Diagnostic::new(
761 "ssh.run.spawn_failed",
762 "SSH run spawn failed".to_string(),
763 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
764 )
765 .with_source(std::sync::Arc::new(reason))
766}
767
768pub fn pty_output_lock_poisoned() -> Diagnostic {
771 Diagnostic::new(
772 "ssh.pty.output_lock_poisoned",
773 "SSH pty output lock poisoned".to_string(),
774 Diagnostic::make_fields(&[]),
775 )
776}
777
778pub fn pty_interrupted_by_cancellation() -> Diagnostic {
781 Diagnostic::new(
782 "ssh.pty.interrupted_by_cancellation",
783 "SSH pty run interrupted by cancellation".to_string(),
784 Diagnostic::make_fields(&[]),
785 )
786}
787
788pub fn pty_borrow_input_failed(reason: Diagnostic) -> Diagnostic {
791 let reason_text = reason.to_string();
792 Diagnostic::new(
793 "ssh.pty.borrow_input_failed",
794 "SSH pty cannot borrow the input pipe".to_string(),
795 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
796 )
797 .with_source(std::sync::Arc::new(reason))
798}
799
800pub fn pty_borrow_output_failed(reason: Diagnostic) -> Diagnostic {
803 let reason_text = reason.to_string();
804 Diagnostic::new(
805 "ssh.pty.borrow_output_failed",
806 "SSH pty cannot borrow the output pipe".to_string(),
807 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
808 )
809 .with_source(std::sync::Arc::new(reason))
810}
811
812pub fn pty_session_init_write_failed(
815 reason: impl std::error::Error + Send + Sync + 'static,
816) -> Diagnostic {
817 let reason_text = reason.to_string();
818 Diagnostic::new(
819 "ssh.pty.session_init_write_failed",
820 "SSH pty session init write failed".to_string(),
821 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
822 )
823 .with_source(std::sync::Arc::new(reason))
824}
825
826pub fn pty_session_init_flush_failed(
829 reason: impl std::error::Error + Send + Sync + 'static,
830) -> Diagnostic {
831 let reason_text = reason.to_string();
832 Diagnostic::new(
833 "ssh.pty.session_init_flush_failed",
834 "SSH pty session init flush failed".to_string(),
835 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
836 )
837 .with_source(std::sync::Arc::new(reason))
838}
839
840pub fn dequeue_task_cancelled(func: &str) -> Diagnostic {
843 let message = format!("{func}: task cancelled");
844 Diagnostic::new(
845 "ssh.dequeue.task_cancelled",
846 message,
847 Diagnostic::make_fields(&[(FIELD_FUNC, func)]),
848 )
849}
850
851pub fn dequeue_server_closed(func: &str) -> Diagnostic {
854 let message = format!("{func}: server is closed");
855 Diagnostic::new(
856 "ssh.dequeue.server_closed",
857 message,
858 Diagnostic::make_fields(&[(FIELD_FUNC, func)]),
859 )
860}
861
862pub fn dequeue_requires_async() -> Diagnostic {
865 Diagnostic::new(
866 "ssh.dequeue.requires_async",
867 format!(
868 "SSH_DEQUEUE requires {KEYWORD_ASYNC}: wrap it as {KEYWORD_LET} $t: {HANDLE_TYPE_NAME}<T> = {KEYWORD_ASYNC} {{ SSH_DEQUEUE($server.server) }}"
869 ),
870 Diagnostic::make_fields(&[]),
871 )
872}
873
874pub fn accept_requires_async() -> Diagnostic {
877 Diagnostic::new(
878 "ssh.accept.requires_async",
879 format!(
880 "SSH_ACCEPT requires {KEYWORD_ASYNC}: wrap it as {KEYWORD_LET} $t: {HANDLE_TYPE_NAME}<T> = {KEYWORD_ASYNC} {{ SSH_ACCEPT($server, $in, $out) }}"
881 ),
882 Diagnostic::make_fields(&[]),
883 )
884}
885
886pub fn pump_channel_requires_async() -> Diagnostic {
889 Diagnostic::new(
890 "ssh.pump_channel.requires_async",
891 format!(
892 "SSH_PUMP_CHANNEL requires {KEYWORD_ASYNC}: pump it in its own task after SSH_DEQUEUE"
893 ),
894 Diagnostic::make_fields(&[]),
895 )
896}
897
898pub fn connect_requires_async() -> Diagnostic {
901 Diagnostic::new(
902 "ssh.connect.requires_async",
903 format!(
904 "SSH_CONNECT requires {KEYWORD_ASYNC}: run it in its own task beside the SSH_PUMP tasks"
905 ),
906 Diagnostic::make_fields(&[]),
907 )
908}
909
910pub fn connect_offline() -> Diagnostic {
912 Diagnostic::new(
913 "ssh.connect.offline",
914 "SSH_CONNECT failed: engine running in --offline mode".to_string(),
915 Diagnostic::make_fields(&[]),
916 )
917}
918
919pub fn connect_username_empty() -> Diagnostic {
922 Diagnostic::new(
923 "ssh.connect.username_empty",
924 "SSH_CONNECT username must not be empty".to_string(),
925 Diagnostic::make_fields(&[]),
926 )
927}
928
929pub fn connect_failed(reason: Diagnostic) -> Diagnostic {
932 let reason_text = reason.to_string();
933 Diagnostic::new(
934 "ssh.connect.failed",
935 "SSH_CONNECT failed".to_string(),
936 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
937 )
938 .with_source(std::sync::Arc::new(reason))
939}
940
941pub fn pty_run_requires_async() -> Diagnostic {
944 Diagnostic::new(
945 "ssh.pty_run.requires_async",
946 format!(
947 "SSH_PTY_RUN requires {KEYWORD_ASYNC}: run it in its own task beside the session pump task"
948 ),
949 Diagnostic::make_fields(&[]),
950 )
951}
952
953pub fn run_requires_async() -> Diagnostic {
955 Diagnostic::new(
956 "ssh.run.requires_async",
957 format!(
958 "SSH_RUN requires {KEYWORD_ASYNC}: run it in its own task beside the session pump task"
959 ),
960 Diagnostic::make_fields(&[]),
961 )
962}
963
964pub fn exec_needs_program() -> Diagnostic {
966 Diagnostic::new(
967 "ssh.exec.needs_program",
968 "SSH_EXEC needs at least a program".to_string(),
969 Diagnostic::make_fields(&[]),
970 )
971}
972
973pub fn exec_username_empty() -> Diagnostic {
976 Diagnostic::new(
977 "ssh.exec.username_empty",
978 "SSH_EXEC username must not be empty".to_string(),
979 Diagnostic::make_fields(&[]),
980 )
981}
982
983pub fn exec_offline() -> Diagnostic {
985 Diagnostic::new(
986 "ssh.exec.offline",
987 "SSH_EXEC failed: engine running in --offline mode".to_string(),
988 Diagnostic::make_fields(&[]),
989 )
990}
991
992pub fn serve_option_empty(option: &str) -> Diagnostic {
996 let message = format!("SSH_SERVE option '{option}' must not be empty");
997 Diagnostic::new(
998 "ssh.serve.option_empty",
999 message,
1000 Diagnostic::make_fields(&[(FIELD_OPTION, option)]),
1001 )
1002}
1003
1004pub fn serve_option_required(option: &str) -> Diagnostic {
1008 let message = format!("SSH_SERVE option '{option}' is required");
1009 Diagnostic::new(
1010 "ssh.serve.option_required",
1011 message,
1012 Diagnostic::make_fields(&[(FIELD_OPTION, option)]),
1013 )
1014}
1015
1016pub fn ephemeral_key_generate_failed(
1020 reason: impl std::error::Error + Send + Sync + 'static,
1021) -> Diagnostic {
1022 let reason_text = reason.to_string();
1023 Diagnostic::new(
1024 "ssh.serve.ephemeral_key_generate_failed",
1025 "generate ephemeral Ed25519 host key".to_string(),
1026 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
1027 )
1028 .with_source(std::sync::Arc::new(reason))
1029}
1030
1031pub fn serve_listener_clone_failed(
1034 reason: impl std::error::Error + Send + Sync + 'static,
1035) -> Diagnostic {
1036 let reason_text = reason.to_string();
1037 Diagnostic::new(
1038 "ssh.serve.listener_clone_failed",
1039 "SSH_SERVE cannot clone its listener".to_string(),
1040 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
1041 )
1042 .with_source(std::sync::Arc::new(reason))
1043}
1044
1045pub fn serve_spawn_failed(reason: impl std::error::Error + Send + Sync + 'static) -> Diagnostic {
1048 let reason_text = reason.to_string();
1049 Diagnostic::new(
1050 "ssh.serve.spawn_failed",
1051 "SSH_SERVE cannot spawn the server thread".to_string(),
1052 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
1053 )
1054 .with_source(std::sync::Arc::new(reason))
1055}
1056
1057pub fn exec_option_must_be_positive(option: &str) -> Diagnostic {
1061 let message = format!("SSH_EXEC option '{option}' must be positive");
1062 Diagnostic::new(
1063 "ssh.exec.option_must_be_positive",
1064 message,
1065 Diagnostic::make_fields(&[(FIELD_OPTION, option)]),
1066 )
1067}
1068
1069pub fn option_must_be_duration(
1074 func: &str,
1075 option: &str,
1076 got: &str,
1077 reason: Diagnostic,
1078) -> Diagnostic {
1079 let reason_text = reason.to_string();
1080 let message = format!("{func} option '{option}' must be a duration, got {got:?}");
1081 Diagnostic::new(
1082 "ssh.option.must_be_duration",
1083 message,
1084 Diagnostic::make_fields(&[
1085 (FIELD_FUNC, func),
1086 (FIELD_OPTION, option),
1087 (FIELD_GOT, got),
1088 (FIELD_ERR, &reason_text),
1089 ]),
1090 )
1091 .with_source(std::sync::Arc::new(reason))
1092}
1093
1094pub fn exec_failed(reason: Diagnostic) -> Diagnostic {
1097 let reason_text = reason.to_string();
1098 Diagnostic::new(
1099 "ssh.exec.failed",
1100 "SSH_EXEC failed".to_string(),
1101 Diagnostic::make_fields(&[(FIELD_ERR, &reason_text)]),
1102 )
1103 .with_source(std::sync::Arc::new(reason))
1104}
1105
1106pub fn send_exit_status_negative(code: i64) -> Diagnostic {
1109 let message = format!("SSH_SEND_EXIT_STATUS code must not be negative: {code}");
1110 Diagnostic::new(
1111 "ssh.send_exit_status.negative",
1112 message,
1113 Diagnostic::make_fields(&[(FIELD_CODE, &code.to_string())]),
1114 )
1115}
1116
1117pub fn send_exit_status_out_of_range(code: i64) -> Diagnostic {
1120 let message = format!("SSH_SEND_EXIT_STATUS code out of range: {code}");
1121 Diagnostic::new(
1122 "ssh.send_exit_status.out_of_range",
1123 message,
1124 Diagnostic::make_fields(&[(FIELD_CODE, &code.to_string())]),
1125 )
1126}
1127
1128#[cfg(test)]
1129mod tests {
1130 use super::*;
1131
1132 fn io_err(msg: &str) -> std::io::Error {
1133 std::io::Error::other(msg.to_string())
1134 }
1135
1136 #[test]
1137 fn each_failure_has_a_distinct_key() {
1138 let err = io_err("boom");
1139 let keys = [
1140 key_path_escapes("SSH_SERVE", "k").key(),
1141 host_key_resolver_failed("SSH_SERVE", &anyhow::anyhow!("boom")).key(),
1142 host_key_generate_failed(io_err("boom")).key(),
1143 host_key_encode_failed(io_err("boom")).key(),
1144 key_guard_failed("SSH_SERVE", &anyhow::anyhow!("boom")).key(),
1145 key_path_join_failed("SSH_SERVE", "k", &anyhow::anyhow!("boom")).key(),
1146 host_key_stat_failed("p", &anyhow::anyhow!("boom")).key(),
1147 host_key_read_failed("SSH_SERVE", "p", &anyhow::anyhow!("boom")).key(),
1148 host_key_parse_failed("SSH_SERVE", "p", io_err("boom")).key(),
1149 host_key_write_failed(&anyhow::anyhow!("boom")).key(),
1150 host_key_must_be_ed25519("SSH_SERVE", "p", &"Ed25519").key(),
1151 host_key_insecure_permissions("SSH_SERVE", "p", 0o644).key(),
1152 pump_output_lock_poisoned().key(),
1153 pump_input_read_failed(&err).key(),
1154 pump_worker_panicked("input worker").key(),
1155 pump_interrupted_by_cancellation().key(),
1156 pump_source_read_failed(&err).key(),
1157 pump_target_lock_poisoned().key(),
1158 pump_func_input_read_failed("SSH run", &err).key(),
1159 pump_output_write_failed(io_err("boom")).key(),
1160 pump_output_flush_failed(io_err("boom")).key(),
1161 pump_borrow_input_failed(pump_output_lock_poisoned()).key(),
1162 pump_borrow_output_failed(pump_output_lock_poisoned()).key(),
1163 pump_wait_runtime_failed(io_err("boom")).key(),
1164 pump_borrow_source_failed(pump_output_lock_poisoned()).key(),
1165 pump_borrow_target_failed(pump_output_lock_poisoned()).key(),
1166 pump_target_write_failed(io_err("boom")).key(),
1167 pump_target_flush_failed(io_err("boom")).key(),
1168 authentication_rejected("SSH_EXEC").key(),
1169 dial_failed("SSH_EXEC", &anyhow::anyhow!("boom")).key(),
1170 auth_exchange_failed("SSH_EXEC", io_err("boom")).key(),
1171 channel_open_failed("SSH_EXEC", io_err("boom")).key(),
1172 exec_request_failed(io_err("boom")).key(),
1173 shell_request_failed(io_err("boom")).key(),
1174 listener_prepare_failed(io_err("boom")).key(),
1175 listener_handoff_failed(io_err("boom")).key(),
1176 listener_failed(io_err("boom")).key(),
1177 client_runtime_build_failed(io_err("boom")).key(),
1178 session_pump_already_finished().key(),
1179 session_wire_queue_saturated().key(),
1180 session_wire_writer_gone().key(),
1181 session_already_pumped().key(),
1182 channel_data_unknown().key(),
1183 channel_pump_gone().key(),
1184 channel_wire_gone_eof_close().key(),
1185 channel_request_unknown().key(),
1186 channel_already_announced().key(),
1187 run_child_read_failed("stdout", &err).key(),
1188 run_output_write_failed(io_err("boom")).key(),
1189 run_output_flush_failed(io_err("boom")).key(),
1190 run_output_lock_poisoned().key(),
1191 run_needs_program().key(),
1192 run_spawn_lost_stderr().key(),
1193 run_interrupted_by_cancellation().key(),
1194 run_borrow_input_failed(pump_output_lock_poisoned()).key(),
1195 run_borrow_output_failed(pump_output_lock_poisoned()).key(),
1196 run_borrow_error_failed(pump_output_lock_poisoned()).key(),
1197 run_spawn_failed(pump_output_lock_poisoned()).key(),
1198 pty_output_lock_poisoned().key(),
1199 pty_interrupted_by_cancellation().key(),
1200 pty_borrow_input_failed(pump_output_lock_poisoned()).key(),
1201 pty_borrow_output_failed(pump_output_lock_poisoned()).key(),
1202 pty_session_init_write_failed(io_err("boom")).key(),
1203 pty_session_init_flush_failed(io_err("boom")).key(),
1204 dequeue_task_cancelled("SSH_DEQUEUE").key(),
1205 dequeue_server_closed("SSH_DEQUEUE").key(),
1206 dequeue_requires_async().key(),
1207 accept_requires_async().key(),
1208 pump_channel_requires_async().key(),
1209 connect_requires_async().key(),
1210 connect_offline().key(),
1211 connect_username_empty().key(),
1212 connect_failed(pump_output_lock_poisoned()).key(),
1213 pty_run_requires_async().key(),
1214 run_requires_async().key(),
1215 exec_needs_program().key(),
1216 exec_username_empty().key(),
1217 exec_offline().key(),
1218 exec_failed(pump_output_lock_poisoned()).key(),
1219 serve_option_empty("username").key(),
1220 serve_option_required("username").key(),
1221 option_must_be_duration(
1222 "SSH_SERVE",
1223 "idle_timeout",
1224 "x",
1225 pump_output_lock_poisoned(),
1226 )
1227 .key(),
1228 ephemeral_key_generate_failed(io_err("boom")).key(),
1229 serve_listener_clone_failed(io_err("boom")).key(),
1230 serve_spawn_failed(io_err("boom")).key(),
1231 exec_option_must_be_positive("timeout").key(),
1232 send_exit_status_negative(-1).key(),
1233 send_exit_status_out_of_range(1 << 40).key(),
1234 ];
1235 let mut seen = std::collections::HashSet::new();
1236 for k in keys {
1237 assert!(seen.insert(k), "duplicate key {k}");
1238 }
1239 }
1240
1241 #[test]
1242 fn shared_modes_keep_one_key() {
1243 assert_eq!(
1244 authentication_rejected("SSH_EXEC").key(),
1245 authentication_rejected("SSH_CONNECT").key()
1246 );
1247 assert_eq!(
1248 dial_failed("SSH_EXEC", &anyhow::anyhow!("boom")).key(),
1249 dial_failed("SSH_CONNECT", &anyhow::anyhow!("boom")).key()
1250 );
1251 assert_eq!(
1252 auth_exchange_failed("SSH_EXEC", io_err("boom")).key(),
1253 auth_exchange_failed("SSH_CONNECT", io_err("boom")).key()
1254 );
1255 assert_eq!(
1256 channel_open_failed("SSH_EXEC", io_err("boom")).key(),
1257 channel_open_failed("SSH_CONNECT", io_err("boom")).key()
1258 );
1259 assert_eq!(
1260 dequeue_task_cancelled("SSH_DEQUEUE").key(),
1261 dequeue_task_cancelled("SSH_ACCEPT").key()
1262 );
1263 assert_eq!(
1264 dequeue_server_closed("SSH_DEQUEUE").key(),
1265 dequeue_server_closed("SSH_ACCEPT").key()
1266 );
1267 assert_eq!(
1268 serve_option_empty("username").key(),
1269 serve_option_empty("password").key()
1270 );
1271 assert_eq!(
1272 serve_option_required("username").key(),
1273 serve_option_required("password").key()
1274 );
1275 assert_eq!(
1276 option_must_be_duration(
1277 "SSH_SERVE",
1278 "idle_timeout",
1279 "x",
1280 pump_output_lock_poisoned(),
1281 )
1282 .key(),
1283 option_must_be_duration("SSH_EXEC", "timeout", "y", pump_output_lock_poisoned()).key()
1284 );
1285 assert_eq!(
1286 exec_option_must_be_positive("timeout").key(),
1287 exec_option_must_be_positive("max_bytes").key()
1288 );
1289 }
1290
1291 #[test]
1292 fn messages_match_canonical_wording() {
1293 let err = io_err("boom");
1294 assert_eq!(
1295 key_path_escapes("SSH_SERVE", "k").message(),
1296 "SSH_SERVE key_path escapes the workspace: k"
1297 );
1298 assert_eq!(
1299 host_key_resolver_failed("SSH_SERVE", &anyhow::anyhow!("boom")).message(),
1300 "SSH_SERVE cannot open the workspace resolver"
1301 );
1302 assert_eq!(
1303 format!(
1304 "{:#}",
1305 anyhow::Error::new(host_key_resolver_failed(
1306 "SSH_SERVE",
1307 &anyhow::anyhow!("boom")
1308 ))
1309 ),
1310 "SSH_SERVE cannot open the workspace resolver: boom"
1311 );
1312 assert_eq!(
1313 host_key_generate_failed(io_err("boom")).message(),
1314 "generate Ed25519 host key"
1315 );
1316 assert_eq!(
1317 format!(
1318 "{:#}",
1319 anyhow::Error::new(host_key_generate_failed(io_err("boom")))
1320 ),
1321 "generate Ed25519 host key: boom"
1322 );
1323 assert_eq!(
1324 host_key_encode_failed(io_err("boom")).message(),
1325 "encode Ed25519 host key"
1326 );
1327 assert_eq!(
1328 format!(
1329 "{:#}",
1330 anyhow::Error::new(host_key_encode_failed(io_err("boom")))
1331 ),
1332 "encode Ed25519 host key: boom"
1333 );
1334 assert_eq!(
1335 key_guard_failed("SSH_SERVE", &anyhow::anyhow!("boom")).message(),
1336 "SSH_SERVE cannot guard the workspace root"
1337 );
1338 assert_eq!(
1339 format!(
1340 "{:#}",
1341 anyhow::Error::new(key_guard_failed("SSH_SERVE", &anyhow::anyhow!("boom")))
1342 ),
1343 "SSH_SERVE cannot guard the workspace root: boom"
1344 );
1345 assert_eq!(
1346 key_path_join_failed("SSH_SERVE", "k", &anyhow::anyhow!("boom")).message(),
1347 "SSH_SERVE key_path escapes the workspace: k"
1348 );
1349 assert_eq!(
1350 format!(
1351 "{:#}",
1352 anyhow::Error::new(key_path_join_failed(
1353 "SSH_SERVE",
1354 "k",
1355 &anyhow::anyhow!("boom")
1356 ))
1357 ),
1358 "SSH_SERVE key_path escapes the workspace: k: boom"
1359 );
1360 assert_eq!(
1361 host_key_stat_failed("p", &anyhow::anyhow!("boom")).message(),
1362 "cannot stat host key p"
1363 );
1364 assert_eq!(
1365 format!(
1366 "{:#}",
1367 anyhow::Error::new(host_key_stat_failed("p", &anyhow::anyhow!("boom")))
1368 ),
1369 "cannot stat host key p: boom"
1370 );
1371 assert_eq!(
1372 host_key_read_failed("SSH_SERVE", "p", &anyhow::anyhow!("boom")).message(),
1373 "SSH_SERVE cannot read host key p"
1374 );
1375 assert_eq!(
1376 format!(
1377 "{:#}",
1378 anyhow::Error::new(host_key_read_failed(
1379 "SSH_SERVE",
1380 "p",
1381 &anyhow::anyhow!("boom")
1382 ))
1383 ),
1384 "SSH_SERVE cannot read host key p: boom"
1385 );
1386 assert_eq!(
1387 host_key_parse_failed("SSH_SERVE", "p", io_err("boom")).message(),
1388 "SSH_SERVE cannot parse host key p"
1389 );
1390 assert_eq!(
1391 format!(
1392 "{:#}",
1393 anyhow::Error::new(host_key_parse_failed("SSH_SERVE", "p", io_err("boom")))
1394 ),
1395 "SSH_SERVE cannot parse host key p: boom"
1396 );
1397 assert_eq!(
1398 host_key_write_failed(&anyhow::anyhow!("boom")).message(),
1399 "boom"
1400 );
1401 assert_eq!(
1402 host_key_must_be_ed25519("SSH_SERVE", "p", &"Ed25519").message(),
1403 "SSH_SERVE host key p must be Ed25519, found \"Ed25519\""
1404 );
1405 assert_eq!(
1406 host_key_insecure_permissions("SSH_SERVE", "p", 0o644).message(),
1407 "SSH_SERVE insecure permissions on host key file p: expected 0600, got 0644"
1408 );
1409 assert_eq!(
1410 pump_output_lock_poisoned().message(),
1411 "SSH pump output lock poisoned"
1412 );
1413 assert_eq!(
1414 pump_input_read_failed(&err).message(),
1415 "SSH pump input pipe read failed: boom"
1416 );
1417 assert_eq!(
1418 pump_worker_panicked("input worker").message(),
1419 "SSH pump input worker panicked"
1420 );
1421 assert_eq!(
1422 pump_interrupted_by_cancellation().message(),
1423 "SSH pump interrupted by cancellation"
1424 );
1425 assert_eq!(
1426 pump_source_read_failed(&err).message(),
1427 "SSH_PUMP source pipe read failed: boom"
1428 );
1429 assert_eq!(
1430 pump_target_lock_poisoned().message(),
1431 "SSH_PUMP target lock poisoned"
1432 );
1433 assert_eq!(
1434 pump_func_input_read_failed("SSH run", &err).message(),
1435 "SSH run input pipe read failed: boom"
1436 );
1437 assert_eq!(
1438 pump_output_write_failed(io_err("boom")).message(),
1439 "SSH pump output pipe write failed"
1440 );
1441 assert_eq!(
1442 format!(
1443 "{:#}",
1444 anyhow::Error::new(pump_output_write_failed(io_err("boom")))
1445 ),
1446 "SSH pump output pipe write failed: boom"
1447 );
1448 assert_eq!(
1449 pump_output_flush_failed(io_err("boom")).message(),
1450 "SSH pump output pipe flush failed"
1451 );
1452 assert_eq!(
1453 format!(
1454 "{:#}",
1455 anyhow::Error::new(pump_output_flush_failed(io_err("boom")))
1456 ),
1457 "SSH pump output pipe flush failed: boom"
1458 );
1459 assert_eq!(
1460 pump_borrow_input_failed(pump_output_lock_poisoned()).message(),
1461 "SSH pump cannot borrow the input pipe"
1462 );
1463 assert_eq!(
1464 format!(
1465 "{:#}",
1466 anyhow::Error::new(pump_borrow_input_failed(pump_output_lock_poisoned()))
1467 ),
1468 "SSH pump cannot borrow the input pipe: SSH pump output lock poisoned"
1469 );
1470 assert_eq!(
1471 pump_borrow_output_failed(pump_output_lock_poisoned()).message(),
1472 "SSH pump cannot borrow the output pipe"
1473 );
1474 assert_eq!(
1475 format!(
1476 "{:#}",
1477 anyhow::Error::new(pump_borrow_output_failed(pump_output_lock_poisoned()))
1478 ),
1479 "SSH pump cannot borrow the output pipe: SSH pump output lock poisoned"
1480 );
1481 assert_eq!(
1482 pump_wait_runtime_failed(io_err("boom")).message(),
1483 "SSH pump wait runtime failed"
1484 );
1485 assert_eq!(
1486 format!(
1487 "{:#}",
1488 anyhow::Error::new(pump_wait_runtime_failed(io_err("boom")))
1489 ),
1490 "SSH pump wait runtime failed: boom"
1491 );
1492 assert_eq!(
1493 pump_borrow_source_failed(pump_output_lock_poisoned()).message(),
1494 "SSH_PUMP cannot borrow the source pipe"
1495 );
1496 assert_eq!(
1497 format!(
1498 "{:#}",
1499 anyhow::Error::new(pump_borrow_source_failed(pump_output_lock_poisoned()))
1500 ),
1501 "SSH_PUMP cannot borrow the source pipe: SSH pump output lock poisoned"
1502 );
1503 assert_eq!(
1504 pump_borrow_target_failed(pump_output_lock_poisoned()).message(),
1505 "SSH_PUMP cannot borrow the target pipe"
1506 );
1507 assert_eq!(
1508 format!(
1509 "{:#}",
1510 anyhow::Error::new(pump_borrow_target_failed(pump_output_lock_poisoned()))
1511 ),
1512 "SSH_PUMP cannot borrow the target pipe: SSH pump output lock poisoned"
1513 );
1514 assert_eq!(
1515 pump_target_write_failed(io_err("boom")).message(),
1516 "SSH_PUMP target pipe write failed"
1517 );
1518 assert_eq!(
1519 format!(
1520 "{:#}",
1521 anyhow::Error::new(pump_target_write_failed(io_err("boom")))
1522 ),
1523 "SSH_PUMP target pipe write failed: boom"
1524 );
1525 assert_eq!(
1526 pump_target_flush_failed(io_err("boom")).message(),
1527 "SSH_PUMP target pipe flush failed"
1528 );
1529 assert_eq!(
1530 format!(
1531 "{:#}",
1532 anyhow::Error::new(pump_target_flush_failed(io_err("boom")))
1533 ),
1534 "SSH_PUMP target pipe flush failed: boom"
1535 );
1536 assert_eq!(
1537 authentication_rejected("SSH_EXEC").message(),
1538 "SSH_EXEC authentication rejected"
1539 );
1540 assert_eq!(
1541 dial_failed("SSH_EXEC", &anyhow::anyhow!("boom")).message(),
1542 "SSH_EXEC dial failed"
1543 );
1544 assert_eq!(
1545 format!(
1546 "{:#}",
1547 anyhow::Error::new(dial_failed("SSH_EXEC", &anyhow::anyhow!("boom")))
1548 ),
1549 "SSH_EXEC dial failed: boom"
1550 );
1551 assert_eq!(
1552 auth_exchange_failed("SSH_EXEC", io_err("boom")).message(),
1553 "SSH_EXEC authentication exchange failed"
1554 );
1555 assert_eq!(
1556 format!(
1557 "{:#}",
1558 anyhow::Error::new(auth_exchange_failed("SSH_EXEC", io_err("boom")))
1559 ),
1560 "SSH_EXEC authentication exchange failed: boom"
1561 );
1562 assert_eq!(
1563 channel_open_failed("SSH_EXEC", io_err("boom")).message(),
1564 "SSH_EXEC channel open failed"
1565 );
1566 assert_eq!(
1567 format!(
1568 "{:#}",
1569 anyhow::Error::new(channel_open_failed("SSH_EXEC", io_err("boom")))
1570 ),
1571 "SSH_EXEC channel open failed: boom"
1572 );
1573 assert_eq!(
1574 exec_request_failed(io_err("boom")).message(),
1575 "SSH_EXEC exec request failed"
1576 );
1577 assert_eq!(
1578 format!(
1579 "{:#}",
1580 anyhow::Error::new(exec_request_failed(io_err("boom")))
1581 ),
1582 "SSH_EXEC exec request failed: boom"
1583 );
1584 assert_eq!(
1585 shell_request_failed(io_err("boom")).message(),
1586 "SSH_CONNECT shell request failed"
1587 );
1588 assert_eq!(
1589 format!(
1590 "{:#}",
1591 anyhow::Error::new(shell_request_failed(io_err("boom")))
1592 ),
1593 "SSH_CONNECT shell request failed: boom"
1594 );
1595 assert_eq!(
1596 listener_prepare_failed(io_err("boom")).message(),
1597 "prepare listener for the runtime"
1598 );
1599 assert_eq!(
1600 format!(
1601 "{:#}",
1602 anyhow::Error::new(listener_prepare_failed(io_err("boom")))
1603 ),
1604 "prepare listener for the runtime: boom"
1605 );
1606 assert_eq!(
1607 listener_handoff_failed(io_err("boom")).message(),
1608 "hand listener to the runtime"
1609 );
1610 assert_eq!(
1611 format!(
1612 "{:#}",
1613 anyhow::Error::new(listener_handoff_failed(io_err("boom")))
1614 ),
1615 "hand listener to the runtime: boom"
1616 );
1617 assert_eq!(
1618 listener_failed(io_err("boom")).message(),
1619 "SSH listener failed"
1620 );
1621 assert_eq!(
1622 format!("{:#}", anyhow::Error::new(listener_failed(io_err("boom")))),
1623 "SSH listener failed: boom"
1624 );
1625 assert_eq!(
1626 client_runtime_build_failed(io_err("boom")).message(),
1627 "build SSH client runtime"
1628 );
1629 assert_eq!(
1630 format!(
1631 "{:#}",
1632 anyhow::Error::new(client_runtime_build_failed(io_err("boom")))
1633 ),
1634 "build SSH client runtime: boom"
1635 );
1636 assert_eq!(
1637 session_pump_already_finished().message(),
1638 "SSH session pump already finished"
1639 );
1640 assert_eq!(
1641 session_wire_queue_saturated().message(),
1642 "SSH session wire queue saturated under backpressure"
1643 );
1644 assert_eq!(
1645 session_wire_writer_gone().message(),
1646 "SSH session wire writer is gone"
1647 );
1648 assert_eq!(
1649 session_already_pumped().message(),
1650 "SSH session already pumped"
1651 );
1652 assert_eq!(channel_data_unknown().message(), "data for unknown channel");
1653 assert_eq!(channel_pump_gone().message(), "pump went away");
1654 assert_eq!(
1655 channel_wire_gone_eof_close().message(),
1656 "wire gone during EOF close"
1657 );
1658 assert_eq!(
1659 channel_request_unknown().message(),
1660 "request for unknown channel"
1661 );
1662 assert_eq!(
1663 channel_already_announced().message(),
1664 "channel already announced"
1665 );
1666 assert_eq!(
1667 run_child_read_failed("stdout", &err).message(),
1668 "SSH run child stdout read failed: boom"
1669 );
1670 assert_eq!(
1671 run_output_write_failed(io_err("boom")).message(),
1672 "SSH run output pipe write failed"
1673 );
1674 assert_eq!(
1675 format!(
1676 "{:#}",
1677 anyhow::Error::new(run_output_write_failed(io_err("boom")))
1678 ),
1679 "SSH run output pipe write failed: boom"
1680 );
1681 assert_eq!(
1682 run_output_flush_failed(io_err("boom")).message(),
1683 "SSH run output pipe flush failed"
1684 );
1685 assert_eq!(
1686 format!(
1687 "{:#}",
1688 anyhow::Error::new(run_output_flush_failed(io_err("boom")))
1689 ),
1690 "SSH run output pipe flush failed: boom"
1691 );
1692 assert_eq!(
1693 run_output_lock_poisoned().message(),
1694 "SSH run output lock poisoned"
1695 );
1696 assert_eq!(
1697 run_needs_program().message(),
1698 "SSH_RUN needs at least a program"
1699 );
1700 assert_eq!(
1701 run_spawn_lost_stderr().message(),
1702 "SSH run spawn lost stderr"
1703 );
1704 assert_eq!(
1705 run_interrupted_by_cancellation().message(),
1706 "SSH run interrupted by cancellation"
1707 );
1708 assert_eq!(
1709 run_borrow_input_failed(pump_output_lock_poisoned()).message(),
1710 "SSH run cannot borrow the input pipe"
1711 );
1712 assert_eq!(
1713 format!(
1714 "{:#}",
1715 anyhow::Error::new(run_borrow_input_failed(pump_output_lock_poisoned()))
1716 ),
1717 "SSH run cannot borrow the input pipe: SSH pump output lock poisoned"
1718 );
1719 assert_eq!(
1720 run_borrow_output_failed(pump_output_lock_poisoned()).message(),
1721 "SSH run cannot borrow the output pipe"
1722 );
1723 assert_eq!(
1724 format!(
1725 "{:#}",
1726 anyhow::Error::new(run_borrow_output_failed(pump_output_lock_poisoned()))
1727 ),
1728 "SSH run cannot borrow the output pipe: SSH pump output lock poisoned"
1729 );
1730 assert_eq!(
1731 run_borrow_error_failed(pump_output_lock_poisoned()).message(),
1732 "SSH run cannot borrow the error pipe"
1733 );
1734 assert_eq!(
1735 format!(
1736 "{:#}",
1737 anyhow::Error::new(run_borrow_error_failed(pump_output_lock_poisoned()))
1738 ),
1739 "SSH run cannot borrow the error pipe: SSH pump output lock poisoned"
1740 );
1741 assert_eq!(
1742 run_spawn_failed(pump_output_lock_poisoned()).message(),
1743 "SSH run spawn failed"
1744 );
1745 assert_eq!(
1746 format!(
1747 "{:#}",
1748 anyhow::Error::new(run_spawn_failed(pump_output_lock_poisoned()))
1749 ),
1750 "SSH run spawn failed: SSH pump output lock poisoned"
1751 );
1752 assert_eq!(
1753 pty_output_lock_poisoned().message(),
1754 "SSH pty output lock poisoned"
1755 );
1756 assert_eq!(
1757 pty_interrupted_by_cancellation().message(),
1758 "SSH pty run interrupted by cancellation"
1759 );
1760 assert_eq!(
1761 pty_borrow_input_failed(pump_output_lock_poisoned()).message(),
1762 "SSH pty cannot borrow the input pipe"
1763 );
1764 assert_eq!(
1765 format!(
1766 "{:#}",
1767 anyhow::Error::new(pty_borrow_input_failed(pump_output_lock_poisoned()))
1768 ),
1769 "SSH pty cannot borrow the input pipe: SSH pump output lock poisoned"
1770 );
1771 assert_eq!(
1772 pty_borrow_output_failed(pump_output_lock_poisoned()).message(),
1773 "SSH pty cannot borrow the output pipe"
1774 );
1775 assert_eq!(
1776 format!(
1777 "{:#}",
1778 anyhow::Error::new(pty_borrow_output_failed(pump_output_lock_poisoned()))
1779 ),
1780 "SSH pty cannot borrow the output pipe: SSH pump output lock poisoned"
1781 );
1782 assert_eq!(
1783 pty_session_init_write_failed(io_err("boom")).message(),
1784 "SSH pty session init write failed"
1785 );
1786 assert_eq!(
1787 format!(
1788 "{:#}",
1789 anyhow::Error::new(pty_session_init_write_failed(io_err("boom")))
1790 ),
1791 "SSH pty session init write failed: boom"
1792 );
1793 assert_eq!(
1794 pty_session_init_flush_failed(io_err("boom")).message(),
1795 "SSH pty session init flush failed"
1796 );
1797 assert_eq!(
1798 format!(
1799 "{:#}",
1800 anyhow::Error::new(pty_session_init_flush_failed(io_err("boom")))
1801 ),
1802 "SSH pty session init flush failed: boom"
1803 );
1804 assert_eq!(
1805 dequeue_task_cancelled("SSH_DEQUEUE").message(),
1806 "SSH_DEQUEUE: task cancelled"
1807 );
1808 assert_eq!(
1809 dequeue_server_closed("SSH_ACCEPT").message(),
1810 "SSH_ACCEPT: server is closed"
1811 );
1812 assert_eq!(
1813 dequeue_requires_async().message(),
1814 "SSH_DEQUEUE requires ASYNC: wrap it as LET $t: HANDLE<T> = ASYNC { SSH_DEQUEUE($server.server) }"
1815 );
1816 assert_eq!(
1817 accept_requires_async().message(),
1818 "SSH_ACCEPT requires ASYNC: wrap it as LET $t: HANDLE<T> = ASYNC { SSH_ACCEPT($server, $in, $out) }"
1819 );
1820 assert_eq!(
1821 pump_channel_requires_async().message(),
1822 "SSH_PUMP_CHANNEL requires ASYNC: pump it in its own task after SSH_DEQUEUE"
1823 );
1824 assert_eq!(
1825 connect_requires_async().message(),
1826 "SSH_CONNECT requires ASYNC: run it in its own task beside the SSH_PUMP tasks"
1827 );
1828 assert_eq!(
1829 connect_offline().message(),
1830 "SSH_CONNECT failed: engine running in --offline mode"
1831 );
1832 assert_eq!(
1833 connect_username_empty().message(),
1834 "SSH_CONNECT username must not be empty"
1835 );
1836 assert_eq!(
1837 connect_failed(pump_output_lock_poisoned()).message(),
1838 "SSH_CONNECT failed"
1839 );
1840 assert_eq!(
1841 format!(
1842 "{:#}",
1843 anyhow::Error::new(connect_failed(pump_output_lock_poisoned()))
1844 ),
1845 "SSH_CONNECT failed: SSH pump output lock poisoned"
1846 );
1847 assert_eq!(
1848 pty_run_requires_async().message(),
1849 "SSH_PTY_RUN requires ASYNC: run it in its own task beside the session pump task"
1850 );
1851 assert_eq!(
1852 run_requires_async().message(),
1853 "SSH_RUN requires ASYNC: run it in its own task beside the session pump task"
1854 );
1855 assert_eq!(
1856 exec_needs_program().message(),
1857 "SSH_EXEC needs at least a program"
1858 );
1859 assert_eq!(
1860 exec_username_empty().message(),
1861 "SSH_EXEC username must not be empty"
1862 );
1863 assert_eq!(
1864 exec_offline().message(),
1865 "SSH_EXEC failed: engine running in --offline mode"
1866 );
1867 assert_eq!(
1868 exec_failed(pump_output_lock_poisoned()).message(),
1869 "SSH_EXEC failed"
1870 );
1871 assert_eq!(
1872 format!(
1873 "{:#}",
1874 anyhow::Error::new(exec_failed(pump_output_lock_poisoned()))
1875 ),
1876 "SSH_EXEC failed: SSH pump output lock poisoned"
1877 );
1878 assert_eq!(
1879 serve_option_empty("username").message(),
1880 "SSH_SERVE option 'username' must not be empty"
1881 );
1882 assert_eq!(
1883 serve_option_required("password").message(),
1884 "SSH_SERVE option 'password' is required"
1885 );
1886 assert_eq!(
1887 option_must_be_duration(
1888 "SSH_SERVE",
1889 "idle_timeout",
1890 "soon",
1891 pump_output_lock_poisoned(),
1892 )
1893 .message(),
1894 "SSH_SERVE option 'idle_timeout' must be a duration, got \"soon\""
1895 );
1896 assert_eq!(
1897 format!(
1898 "{:#}",
1899 anyhow::Error::new(option_must_be_duration(
1900 "SSH_SERVE",
1901 "idle_timeout",
1902 "soon",
1903 pump_output_lock_poisoned(),
1904 ))
1905 ),
1906 "SSH_SERVE option 'idle_timeout' must be a duration, got \"soon\": SSH pump output lock poisoned"
1907 );
1908 assert_eq!(
1909 option_must_be_duration("SSH_EXEC", "timeout", "soon", pump_output_lock_poisoned())
1910 .message(),
1911 "SSH_EXEC option 'timeout' must be a duration, got \"soon\""
1912 );
1913 assert_eq!(
1914 ephemeral_key_generate_failed(io_err("boom")).message(),
1915 "generate ephemeral Ed25519 host key"
1916 );
1917 assert_eq!(
1918 format!(
1919 "{:#}",
1920 anyhow::Error::new(ephemeral_key_generate_failed(io_err("boom")))
1921 ),
1922 "generate ephemeral Ed25519 host key: boom"
1923 );
1924 assert_eq!(
1925 serve_listener_clone_failed(io_err("boom")).message(),
1926 "SSH_SERVE cannot clone its listener"
1927 );
1928 assert_eq!(
1929 format!(
1930 "{:#}",
1931 anyhow::Error::new(serve_listener_clone_failed(io_err("boom")))
1932 ),
1933 "SSH_SERVE cannot clone its listener: boom"
1934 );
1935 assert_eq!(
1936 serve_spawn_failed(io_err("boom")).message(),
1937 "SSH_SERVE cannot spawn the server thread"
1938 );
1939 assert_eq!(
1940 format!(
1941 "{:#}",
1942 anyhow::Error::new(serve_spawn_failed(io_err("boom")))
1943 ),
1944 "SSH_SERVE cannot spawn the server thread: boom"
1945 );
1946 assert_eq!(
1947 exec_option_must_be_positive("timeout").message(),
1948 "SSH_EXEC option 'timeout' must be positive"
1949 );
1950 assert_eq!(
1951 send_exit_status_negative(-1).message(),
1952 "SSH_SEND_EXIT_STATUS code must not be negative: -1"
1953 );
1954 assert_eq!(
1955 send_exit_status_out_of_range(1 << 40).message(),
1956 "SSH_SEND_EXIT_STATUS code out of range: 1099511627776"
1957 );
1958 }
1959}