-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.rs
More file actions
989 lines (827 loc) · 34 KB
/
Copy patherrors.rs
File metadata and controls
989 lines (827 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
//! Error types for the Release command handler
//!
//! # Design Decision: Boxed Error Sources
//!
//! All step-related error variants use `Box<dyn std::error::Error + Send + Sync>`
//! as the source type rather than concrete step error types. This design choice
//! was made because:
//!
//! 1. **Many heterogeneous step types**: The release workflow involves 15+ steps,
//! each with its own error type (`CommandError`, `TrackerProjectGeneratorError`,
//! `DeployComposeFilesStepError`, etc.). Using concrete types would require
//! either a massive wrapper enum or many separate error variants.
//!
//! 2. **Extensibility**: New steps can be added without modifying the error enum.
//!
//! 3. **Uniform error handling**: All step errors can be handled uniformly with
//! the `with_step` helper pattern.
//!
//! **Trade-off**: We lose the ability to pattern match on the concrete source type
//! and `Traceable::trace_source()` returns `None` for boxed errors. However, the
//! error message is preserved via `to_string()`, and the trace file captures full
//! context for debugging.
//!
//! **Preferred pattern**: In cases where there are fewer, well-defined error sources,
//! prefer using concrete types with `#[source]` for better type safety and traceability.
use crate::application::errors::{InvalidStateError, PersistenceError, ReleaseWorkflowStep};
use crate::shared::error::{ErrorKind, Traceable};
/// Type alias for boxed step errors to reduce verbosity
pub type BoxedStepError = Box<dyn std::error::Error + Send + Sync>;
/// Comprehensive error type for the `ReleaseCommandHandler`
///
/// This error type captures all possible failures that can occur during
/// software release operations. Each variant provides detailed context
/// and actionable troubleshooting guidance.
#[derive(Debug, thiserror::Error)]
pub enum ReleaseCommandHandlerError {
/// Environment was not found in the repository
#[error("Environment not found: {name}")]
EnvironmentNotFound {
/// The name of the environment that was not found
name: String,
},
/// Instance IP address is not available (required for deployment)
///
/// The release command requires the instance IP address to deploy files
/// to the remote host. This IP should be available after provisioning.
#[error("Instance IP address is not available for environment '{name}'. The provision step should have set this value.")]
MissingInstanceIp {
/// The name of the environment missing the instance IP
name: String,
},
/// Environment is in an invalid state for release
#[error("Environment is in an invalid state for release: {0}")]
InvalidState(#[from] InvalidStateError),
/// Failed to persist environment state
#[error("Failed to persist environment state: {0}")]
StatePersistence(#[from] PersistenceError),
/// Template rendering failed
#[error("Template rendering failed: {message}")]
TemplateRendering {
/// Description of the rendering failure
message: String,
/// The underlying error from the template step
#[source]
source: BoxedStepError,
},
/// Tracker storage directory creation failed
#[error("Tracker storage creation failed: {message}")]
TrackerStorageCreation {
/// Description of the failure
message: String,
/// The underlying error from the storage creation step
#[source]
source: BoxedStepError,
},
/// Tracker database initialization failed
#[error("Tracker database initialization failed: {message}")]
TrackerDatabaseInit {
/// Description of the failure
message: String,
/// The underlying error from the database init step
#[source]
source: BoxedStepError,
},
/// Prometheus storage directory creation failed
#[error("Prometheus storage creation failed: {message}")]
PrometheusStorageCreation {
/// Description of the failure
message: String,
/// The underlying error from the storage creation step
#[source]
source: BoxedStepError,
},
/// Grafana storage directory creation failed
#[error("Grafana storage creation failed: {message}")]
GrafanaStorageCreation {
/// Description of the failure
message: String,
/// The underlying error from the storage creation step
#[source]
source: BoxedStepError,
},
/// `MySQL` storage directory creation failed
#[error("MySQL storage creation failed: {message}")]
MysqlStorageCreation {
/// Description of the failure
message: String,
/// The underlying error from the storage creation step
#[source]
source: BoxedStepError,
},
/// Backup template rendering failed
#[error("Backup template rendering failed: {message}")]
RenderBackupTemplatesFailed {
/// Description of the failure
message: String,
/// The underlying error from the rendering step
#[source]
source: BoxedStepError,
/// The release step that failed
step: ReleaseWorkflowStep,
},
/// Backup configuration deployment failed
#[error("Backup configuration deployment failed: {message}")]
DeployBackupConfigFailed {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
/// The release step that failed
step: ReleaseWorkflowStep,
},
/// Backup crontab installation failed
#[error("Backup crontab installation failed: {message}")]
InstallBackupCrontabFailed {
/// Description of the failure
message: String,
/// The underlying error from the installation step
#[source]
source: BoxedStepError,
/// The release step that failed
step: ReleaseWorkflowStep,
},
/// Backup storage directory creation failed
#[error("Backup storage creation failed: {message}")]
CreateBackupStorageFailed {
/// Description of the failure
message: String,
/// The underlying error from the storage creation step
#[source]
source: BoxedStepError,
/// The release step that failed
step: ReleaseWorkflowStep,
},
/// Caddy configuration deployment failed
#[error("Caddy configuration deployment failed: {message}")]
CaddyConfigDeployment {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
},
/// Tracker configuration deployment failed
#[error("Tracker configuration deployment failed: {message}")]
TrackerConfigDeployment {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
},
/// Grafana provisioning deployment failed
#[error("Grafana provisioning deployment failed: {message}")]
GrafanaProvisioningDeployment {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
},
/// Prometheus configuration deployment failed
#[error("Prometheus configuration deployment failed: {message}")]
PrometheusConfigDeployment {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
},
/// Docker Compose files deployment failed
#[error("Docker Compose deployment failed: {message}")]
ComposeFilesDeployment {
/// Description of the failure
message: String,
/// The underlying error from the deployment step
#[source]
source: BoxedStepError,
},
/// Release operation failed
#[error("Release operation failed for environment '{name}': {message}")]
ReleaseOperationFailed {
/// The name of the environment
name: String,
/// Description of the failure
message: String,
},
}
impl From<crate::domain::environment::repository::RepositoryError> for ReleaseCommandHandlerError {
fn from(e: crate::domain::environment::repository::RepositoryError) -> Self {
Self::StatePersistence(e.into())
}
}
impl From<crate::domain::environment::state::StateTypeError> for ReleaseCommandHandlerError {
fn from(e: crate::domain::environment::state::StateTypeError) -> Self {
Self::InvalidState(e.into())
}
}
impl Traceable for ReleaseCommandHandlerError {
fn trace_format(&self) -> String {
match self {
Self::EnvironmentNotFound { name } => {
format!("ReleaseCommandHandlerError: Environment not found - {name}")
}
Self::MissingInstanceIp { name } => {
format!("ReleaseCommandHandlerError: Instance IP not available for environment '{name}'")
}
Self::InvalidState(e) => {
format!("ReleaseCommandHandlerError: Invalid state for release - {e}")
}
Self::StatePersistence(e) => {
format!("ReleaseCommandHandlerError: Failed to persist environment state - {e}")
}
Self::TemplateRendering { message, .. } => {
format!("ReleaseCommandHandlerError: Template rendering failed - {message}")
}
Self::TrackerStorageCreation { message, .. } => {
format!("ReleaseCommandHandlerError: Tracker storage creation failed - {message}")
}
Self::TrackerDatabaseInit { message, .. } => {
format!("ReleaseCommandHandlerError: Tracker database initialization failed - {message}")
}
Self::PrometheusStorageCreation { message, .. } => {
format!(
"ReleaseCommandHandlerError: Prometheus storage creation failed - {message}"
)
}
Self::GrafanaStorageCreation { message, .. } => {
format!("ReleaseCommandHandlerError: Grafana storage creation failed - {message}")
}
Self::MysqlStorageCreation { message, .. } => {
format!("ReleaseCommandHandlerError: MySQL storage creation failed - {message}")
}
Self::RenderBackupTemplatesFailed { message, .. } => {
format!("ReleaseCommandHandlerError: Backup template rendering failed - {message}")
}
Self::CreateBackupStorageFailed { message, .. } => {
format!("ReleaseCommandHandlerError: Backup storage creation failed - {message}")
}
Self::DeployBackupConfigFailed { message, .. } => {
format!("ReleaseCommandHandlerError: Backup configuration deployment failed - {message}")
}
Self::InstallBackupCrontabFailed { message, .. } => {
format!(
"ReleaseCommandHandlerError: Backup crontab installation failed - {message}"
)
}
Self::CaddyConfigDeployment { message, .. } => {
format!(
"ReleaseCommandHandlerError: Caddy configuration deployment failed - {message}"
)
}
Self::TrackerConfigDeployment { message, .. } => {
format!(
"ReleaseCommandHandlerError: Tracker configuration deployment failed - {message}"
)
}
Self::GrafanaProvisioningDeployment { message, .. } => {
format!(
"ReleaseCommandHandlerError: Grafana provisioning deployment failed - {message}"
)
}
Self::PrometheusConfigDeployment { message, .. } => {
format!(
"ReleaseCommandHandlerError: Prometheus configuration deployment failed - {message}"
)
}
Self::ComposeFilesDeployment { message, .. } => {
format!("ReleaseCommandHandlerError: Docker Compose deployment failed - {message}")
}
Self::ReleaseOperationFailed { name, message } => {
format!(
"ReleaseCommandHandlerError: Release operation failed for '{name}' - {message}"
)
}
}
}
fn trace_source(&self) -> Option<&dyn Traceable> {
// Box<dyn Error> doesn't implement Traceable, so we return None for all
// step-related errors. The error message is preserved via `to_string()`
// and the trace file captures full context for debugging.
match self {
Self::EnvironmentNotFound { .. }
| Self::MissingInstanceIp { .. }
| Self::InvalidState(_)
| Self::StatePersistence(_)
| Self::TemplateRendering { .. }
| Self::TrackerStorageCreation { .. }
| Self::TrackerDatabaseInit { .. }
| Self::PrometheusStorageCreation { .. }
| Self::GrafanaStorageCreation { .. }
| Self::MysqlStorageCreation { .. }
| Self::RenderBackupTemplatesFailed { .. }
| Self::CreateBackupStorageFailed { .. }
| Self::DeployBackupConfigFailed { .. }
| Self::InstallBackupCrontabFailed { .. }
| Self::CaddyConfigDeployment { .. }
| Self::TrackerConfigDeployment { .. }
| Self::GrafanaProvisioningDeployment { .. }
| Self::PrometheusConfigDeployment { .. }
| Self::ComposeFilesDeployment { .. }
| Self::ReleaseOperationFailed { .. } => None,
}
}
fn error_kind(&self) -> ErrorKind {
match self {
Self::EnvironmentNotFound { .. }
| Self::MissingInstanceIp { .. }
| Self::InvalidState(_) => ErrorKind::Configuration,
Self::StatePersistence(_) => ErrorKind::StatePersistence,
Self::TemplateRendering { .. } => ErrorKind::TemplateRendering,
Self::TrackerStorageCreation { .. }
| Self::TrackerDatabaseInit { .. }
| Self::PrometheusStorageCreation { .. }
| Self::GrafanaStorageCreation { .. }
| Self::MysqlStorageCreation { .. }
| Self::RenderBackupTemplatesFailed { .. }
| Self::CreateBackupStorageFailed { .. }
| Self::DeployBackupConfigFailed { .. }
| Self::InstallBackupCrontabFailed { .. }
| Self::CaddyConfigDeployment { .. }
| Self::TrackerConfigDeployment { .. }
| Self::GrafanaProvisioningDeployment { .. }
| Self::PrometheusConfigDeployment { .. }
| Self::ComposeFilesDeployment { .. }
| Self::ReleaseOperationFailed { .. } => ErrorKind::InfrastructureOperation,
}
}
}
impl ReleaseCommandHandlerError {
/// Provides detailed troubleshooting guidance for this error
///
/// Returns context-specific help text that guides users toward resolving
/// the issue. This implements the project's tiered help system pattern
/// for actionable error messages.
///
/// # Examples
///
/// ```rust
/// use torrust_tracker_deployer_lib::application::command_handlers::release::ReleaseCommandHandlerError;
///
/// let error = ReleaseCommandHandlerError::EnvironmentNotFound {
/// name: "my-env".to_string(),
/// };
///
/// let help = error.help();
/// assert!(help.contains("Environment Not Found"));
/// assert!(help.contains("Troubleshooting"));
/// ```
#[must_use]
#[allow(clippy::too_many_lines)]
pub fn help(&self) -> &'static str {
match self {
Self::EnvironmentNotFound { .. } => {
"Environment Not Found - Troubleshooting:
1. Verify the environment name is correct
2. Check if the environment was created:
ls data/
3. If the environment doesn't exist, create it first:
cargo run -- create environment --env-file <config.json>
4. If the environment was previously destroyed, recreate it
Common causes:
- Typo in environment name
- Environment was destroyed
- Working in the wrong directory
For more information, see docs/user-guide/commands.md"
}
Self::InvalidState { .. } => {
"Invalid Environment State - Troubleshooting:
1. The release command requires the environment to be in Configured state
2. Check the current environment state:
cat data/<env-name>/environment.json
3. If the environment is not configured, run:
cargo run -- configure <env-name>
4. If the environment is in a failed state, resolve the issue first
State progression for release:
Created → Provisioned → Configured → Released
For more information, see docs/user-guide/commands.md"
}
Self::MissingInstanceIp { .. } => {
"Missing Instance IP Address - Troubleshooting:
The release command requires the instance IP address to deploy files to the
remote host. This IP should be automatically set during provisioning.
1. Check if the environment was provisioned correctly:
cat data/<env-name>/environment.json
Look for the 'instance_ip' field in runtime_outputs
2. If instance_ip is null, the provision step may have failed:
cargo run -- provision <env-name>
3. For registered instances, ensure the IP was provided during registration
4. If using LXD, verify the VM is running and has an IP:
lxc list
Common causes:
- Provision step failed or was interrupted
- VM/container has no network connectivity
- DHCP lease not yet assigned
- Registration was incomplete
For more information, see docs/user-guide/commands.md"
}
Self::StatePersistence(_) => {
"State Persistence Failed - Troubleshooting:
1. Check file system permissions for the data directory
2. Verify available disk space: df -h
3. Ensure no other process is accessing the environment files
4. Check for file system errors: dmesg | tail
5. Verify the data directory is writable
State files are stored in: data/<env-name>/
If the problem persists, report it with full system details."
}
Self::TemplateRendering { .. } => {
"Template Rendering Failed - Troubleshooting:
1. Check that template files exist in the templates directory
2. Verify template syntax is valid
3. Check that all required template variables are provided
4. Verify file system permissions for the build directory
Common causes:
- Missing template files
- Invalid template syntax
- Insufficient disk space
- Permission denied on build directory
For more information, see docs/user-guide/commands.md"
}
Self::TrackerStorageCreation { .. } => {
"Tracker Storage Creation Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the instance has sufficient disk space:
df -h
3. Verify the Ansible playbook exists:
ls templates/ansible/create-tracker-storage.yml
4. Check Ansible execution permissions
5. Review the error message above for specific details
Common causes:
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::TrackerDatabaseInit { .. } => {
"Tracker Database Initialization Failed - Troubleshooting:
1. Verify the tracker storage directories were created:
ssh <user>@<instance-ip> 'ls -la /opt/torrust/storage/tracker/lib/database'
2. Check that the instance has sufficient disk space:
df -h
3. Verify the Ansible playbook exists:
ls templates/ansible/init-tracker-database.yml
4. Check file permissions on the database directory
5. Review the error message above for specific details
Common causes:
- Storage directories don't exist (run CreateTrackerStorage step first)
- Insufficient disk space on target instance
- Permission denied on database directory
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::PrometheusStorageCreation { .. } => {
"Prometheus Storage Creation Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the instance has sufficient disk space:
df -h
3. Verify the Ansible playbook exists:
ls templates/ansible/create-prometheus-storage.yml
4. Check Ansible execution permissions
5. Review the error message above for specific details
Common causes:
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::GrafanaStorageCreation { .. } => {
"Grafana Storage Creation Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the instance has sufficient disk space:
df -h
3. Verify the Ansible playbook exists:
ls templates/ansible/create-grafana-storage.yml
4. Check Ansible execution permissions
5. Review the error message above for specific details
Common causes:
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::MysqlStorageCreation { .. } => {
"MySQL Storage Creation Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the instance has sufficient disk space:
df -h
3. Verify the Ansible playbook exists:
ls templates/ansible/create-mysql-storage.yml
4. Check Ansible execution permissions
5. Review the error message above for specific details
Common causes:
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::RenderBackupTemplatesFailed { .. } => {
"Backup Template Rendering Failed - Troubleshooting:
1. Verify backup configuration is present in environment
2. Check template files exist:
ls templates/backup/
3. Verify backup templates are valid:
- backup.conf.tera should exist
- backup-paths.txt should exist
4. Check template rendering permissions
5. Review the error message above for specific details"
}
Self::CreateBackupStorageFailed { .. } => {
"Backup Storage Creation Failed - Troubleshooting:
1. Verify SSH connection to remote host
2. Check Ansible playbook exists:
ls templates/ansible/create-backup-storage.yml
3. Check remote host permissions:
ssh <user>@<host> 'ls -la /opt/torrust/storage/'
4. Verify disk space on remote host:
ssh <user>@<host> 'df -h'
5. Review Ansible playbook execution logs above"
}
Self::DeployBackupConfigFailed { .. } => {
"Backup Configuration Deployment Failed - Troubleshooting:
1. Verify SSH connection to remote host
2. Check Ansible playbook exists:
ls templates/ansible/deploy-backup-config.yml
3. Verify remote storage directory exists:
ssh <user>@<host> 'ls -la /opt/torrust/storage/backup/'
4. Check file permissions on remote host
5. Review Ansible playbook execution logs above"
}
Self::InstallBackupCrontabFailed { .. } => {
"Backup Crontab Installation Failed - Troubleshooting:
1. Verify SSH connection to remote host:
ssh <user>@<host>
2. Check Ansible playbook exists:
ls templates/ansible/install-backup-crontab.yml
3. Verify maintenance script is in build directory:
ls build/<env-name>/backup/etc/maintenance-backup.sh
4. Verify crontab entry is generated:
ls build/<env-name>/backup/etc/maintenance-backup.cron
5. Check that cron daemon is running on target:
ssh <user>@<host> 'systemctl status cron'
6. Check file permissions and ownership on target:
ssh <user>@<host> 'ls -la /usr/local/bin/maintenance-backup.sh'
ssh <user>@<host> 'ls -la /etc/cron.d/tracker-backup'
Common causes:
- Cron daemon not installed or running
- Permission denied on cron directory
- Insufficient disk space on target
- SSH authentication failure
- Ansible playbook not found
For more information, see docs/user-guide/commands.md"
}
Self::CaddyConfigDeployment { .. } => {
"Caddy Configuration Deployment Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the Caddyfile was generated in the build directory:
ls build/<env-name>/caddy/Caddyfile
3. Verify the Ansible playbook exists:
ls templates/ansible/deploy-caddy-config.yml
4. Check that the instance has sufficient disk space:
df -h
5. Review the error message above for specific details
Common causes:
- Caddyfile not generated (HTTPS not configured)
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::TrackerConfigDeployment { .. } => {
"Tracker Configuration Deployment Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the tracker configuration was generated in the build directory:
ls build/<env-name>/tracker/
3. Verify the Ansible playbook exists:
ls templates/ansible/deploy-tracker-config.yml
4. Check that the instance has sufficient disk space:
df -h
5. Review the error message above for specific details
Common causes:
- Configuration files not generated
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::GrafanaProvisioningDeployment { .. } => {
"Grafana Provisioning Deployment Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the Grafana provisioning files were generated:
ls build/<env-name>/grafana/
3. Verify the Ansible playbook exists:
ls templates/ansible/deploy-grafana-provisioning.yml
4. Check that the instance has sufficient disk space:
df -h
5. Review the error message above for specific details
Common causes:
- Provisioning files not generated
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::PrometheusConfigDeployment { .. } => {
"Prometheus Configuration Deployment Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that the Prometheus configuration was generated:
ls build/<env-name>/prometheus/
3. Verify the Ansible playbook exists:
ls templates/ansible/deploy-prometheus-config.yml
4. Check that the instance has sufficient disk space:
df -h
5. Review the error message above for specific details
Common causes:
- Configuration files not generated
- Insufficient disk space on target instance
- Permission denied on target directories
- Ansible playbook not found
- Network connectivity issues
For more information, see docs/user-guide/commands.md"
}
Self::ComposeFilesDeployment { .. } => {
"Docker Compose Deployment Failed - Troubleshooting:
1. Verify the build directory exists and contains expected files:
ls build/<env-name>/docker-compose/
2. Check that the target instance is reachable:
ssh <user>@<instance-ip>
3. Ensure Ansible playbook executed successfully
4. Review the error message above for specific details
5. Check file permissions and disk space on target
Common causes:
- Build directory not found or incomplete
- Network connectivity issues
- SSH authentication failure
- Insufficient permissions on target
- Disk space issues on target instance
For more information, see docs/user-guide/commands.md"
}
Self::ReleaseOperationFailed { .. } => {
"Release Operation Failed - Troubleshooting:
1. Verify the target instance is reachable:
ssh <user>@<instance-ip>
2. Check that required software is installed on the target
3. Review the error message above for specific details
4. Check network connectivity and firewall rules
5. Verify SSH credentials are correct
Common causes:
- Network connectivity issues
- SSH authentication failure
- Target instance not running
- Insufficient permissions on target
For more information, see docs/user-guide/commands.md"
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::io;
/// Helper function to create a boxed error for testing
fn make_boxed_error(msg: &str) -> BoxedStepError {
Box::new(io::Error::other(msg))
}
#[test]
fn it_should_provide_help_for_environment_not_found() {
let error = ReleaseCommandHandlerError::EnvironmentNotFound {
name: "test-env".to_string(),
};
let help = error.help();
assert!(help.contains("Environment Not Found"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_provide_help_for_invalid_state() {
let error = ReleaseCommandHandlerError::InvalidState(InvalidStateError {
expected: "configured".to_string(),
actual: "created".to_string(),
});
let help = error.help();
assert!(help.contains("Invalid Environment State"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_provide_help_for_state_persistence() {
let error = ReleaseCommandHandlerError::StatePersistence(PersistenceError::NotFound);
let help = error.help();
assert!(help.contains("State Persistence"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_provide_help_for_template_rendering() {
let error = ReleaseCommandHandlerError::TemplateRendering {
message: "Test error".to_string(),
source: make_boxed_error("underlying error"),
};
let help = error.help();
assert!(help.contains("Template Rendering"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_provide_help_for_release_operation_failed() {
let error = ReleaseCommandHandlerError::ReleaseOperationFailed {
name: "test-env".to_string(),
message: "Connection refused".to_string(),
};
let help = error.help();
assert!(help.contains("Release Operation Failed"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_provide_help_for_missing_instance_ip() {
let error = ReleaseCommandHandlerError::MissingInstanceIp {
name: "test-env".to_string(),
};
let help = error.help();
assert!(help.contains("Missing Instance IP"));
assert!(help.contains("Troubleshooting"));
}
#[test]
fn it_should_have_help_for_all_error_variants() {
let errors: Vec<ReleaseCommandHandlerError> = vec![
ReleaseCommandHandlerError::EnvironmentNotFound {
name: "test".to_string(),
},
ReleaseCommandHandlerError::MissingInstanceIp {
name: "test".to_string(),
},
ReleaseCommandHandlerError::InvalidState(InvalidStateError {
expected: "configured".to_string(),
actual: "created".to_string(),
}),
ReleaseCommandHandlerError::StatePersistence(PersistenceError::NotFound),
ReleaseCommandHandlerError::TemplateRendering {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::TrackerStorageCreation {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::TrackerDatabaseInit {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::PrometheusStorageCreation {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::GrafanaStorageCreation {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::MysqlStorageCreation {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::CaddyConfigDeployment {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::TrackerConfigDeployment {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::GrafanaProvisioningDeployment {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::PrometheusConfigDeployment {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::ComposeFilesDeployment {
message: "test".to_string(),
source: make_boxed_error("test"),
},
ReleaseCommandHandlerError::ReleaseOperationFailed {
name: "test".to_string(),
message: "error".to_string(),
},
];
for error in errors {
let help = error.help();
assert!(!help.is_empty(), "Help text should not be empty");
assert!(help.len() > 50, "Help should be detailed");
}
}
}