@@ -238,6 +238,7 @@ func migrateApplyRun(cmd *cobra.Command, args []string, flags migrateApplyFlags,
238
238
}
239
239
pending , err := ex .Pending (ctx )
240
240
if err != nil && ! errors .Is (err , migrate .ErrNoPendingFiles ) {
241
+ mr .RecordPlanError (cmd , flags , err .Error ())
241
242
return err
242
243
}
243
244
noPending := errors .Is (err , migrate .ErrNoPendingFiles )
@@ -464,6 +465,35 @@ func (r *MigrateReport) RecordTargetID(ctx context.Context) error {
464
465
return nil
465
466
}
466
467
468
+ // RecordPlanError records any errors that occurred during the planning phase. i.e., when calling to ex.Pending.
469
+ func (r * MigrateReport ) RecordPlanError (cmd * cobra.Command , flags migrateApplyFlags , planerr string ) {
470
+ if ! r .CloudEnabled (cmd .Context ()) {
471
+ return
472
+ }
473
+ var ver string
474
+ if rev , err := r .rrw .CurrentRevision (cmd .Context ()); err == nil {
475
+ ver = rev .Version
476
+ }
477
+ r .done (& cloudapi.ReportMigrationInput {
478
+ ProjectName : r .env .config .cloud .Project ,
479
+ EnvName : r .env .Name ,
480
+ DirName : r .DirName (flags ),
481
+ AtlasVersion : operatorVersion (),
482
+ Target : cloudapi.DeployedTargetInput {
483
+ ID : r .id ,
484
+ Schema : r .client .URL .Schema ,
485
+ URL : r .client .URL .Redacted (),
486
+ },
487
+ StartTime : r .log .Start ,
488
+ EndTime : r .log .End ,
489
+ FromVersion : r .log .Current ,
490
+ ToVersion : r .log .Target ,
491
+ CurrentVersion : ver ,
492
+ Error : & planerr ,
493
+ Log : planerr ,
494
+ })
495
+ }
496
+
467
497
// Done closes and flushes this report.
468
498
func (r * MigrateReport ) Done (cmd * cobra.Command , flags migrateApplyFlags ) error {
469
499
if ! r .CloudEnabled (cmd .Context ()) {
@@ -481,21 +511,10 @@ func (r *MigrateReport) Done(cmd *cobra.Command, flags migrateApplyFlags) error
481
511
default :
482
512
ver = rev .Version
483
513
}
484
- dirName := flags .dirURL
485
- switch u , err := url .Parse (flags .dirURL ); {
486
- case err != nil :
487
- // Local directories are reported as (dangling)
488
- // deployments without a directory.
489
- case u .Scheme == cmdmigrate .DirTypeFile :
490
- dirName = cloudapi .DefaultDirName
491
- // Directory slug.
492
- default :
493
- dirName = path .Join (u .Host , u .Path )
494
- }
495
514
r .done (& cloudapi.ReportMigrationInput {
496
515
ProjectName : r .env .config .cloud .Project ,
497
516
EnvName : r .env .Name ,
498
- DirName : dirName ,
517
+ DirName : r . DirName ( flags ) ,
499
518
AtlasVersion : operatorVersion (),
500
519
Target : cloudapi.DeployedTargetInput {
501
520
ID : r .id ,
@@ -551,6 +570,22 @@ func (r *MigrateReport) Done(cmd *cobra.Command, flags migrateApplyFlags) error
551
570
return err
552
571
}
553
572
573
+ // DirName returns the directory name for the report.
574
+ func (r * MigrateReport ) DirName (flags migrateApplyFlags ) string {
575
+ dirName := flags .dirURL
576
+ switch u , err := url .Parse (flags .dirURL ); {
577
+ case err != nil :
578
+ // Local directories are reported as (dangling)
579
+ // deployments without a directory.
580
+ case u .Scheme == cmdmigrate .DirTypeFile :
581
+ dirName = cloudapi .DefaultDirName
582
+ // Directory slug.
583
+ default :
584
+ dirName = path .Join (u .Host , u .Path )
585
+ }
586
+ return dirName
587
+ }
588
+
554
589
// CloudEnabled reports if cloud reporting is enabled.
555
590
func (r * MigrateReport ) CloudEnabled (ctx context.Context ) bool {
556
591
if r .env == nil || r .env .cloud == nil {
0 commit comments