data_shifter 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +1 -3
- data/lib/data_shifter/internal/rake_exception_reporting.rb +27 -0
- data/lib/data_shifter/internal/rake_setup_output.rb +69 -0
- data/lib/data_shifter/railtie.rb +10 -6
- data/lib/data_shifter/shift.rb +7 -1
- data/lib/data_shifter/version.rb +1 -1
- data/lib/data_shifter.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ebcb5560026f1fcfda0f56953e6a3e139d5fd831c5bb935f352b214c526a7c9
|
|
4
|
+
data.tar.gz: 7b8d142da33da3ead2adc2033a7ad6ab35b9d280da9b50704301d5f0ab093428
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f104c5879fc422025eb752313da24db5a56af3ba2494adf47e7247e49cdcf3ddbd0d91129dafde8a911580e72dc4ae4229b90f7ff081fbd1c2dee20716672959
|
|
7
|
+
data.tar.gz: df5cd362bbb77d66f6d555e5483471429ee1e2c9c089272d39a342ca0967e3de9165a482bc14d50618efc9061763fbac61faf6f14e16a44243a4cc8925aa76ea
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
* N/A
|
|
6
6
|
|
|
7
|
+
## [0.3.2]
|
|
8
|
+
|
|
9
|
+
* [Bugfix] Rake tasks exit quietly after a failed shift run when the shift already printed its failure summary; failures before that summary are still reported on stderr. Replaces rescuing only `Axn::Failure`, which missed most re-raised exceptions from `run!`.
|
|
10
|
+
* [Changed] Setup failures (load, constantize, etc.) print a short framed report on stderr with rake task, file path (relative to `Rails.root`), exception, and a Rails-cleaned backtrace (capped) instead of a full `Exception#full_message` dump.
|
|
11
|
+
|
|
7
12
|
## [0.3.1]
|
|
8
13
|
|
|
9
14
|
* [Bugfix] No longer swallowing unexpected exceptions (errors in *loading* a data shift still need to be reported). No change to handling of exceptions raised while *running* a shift.
|
data/Rakefile
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/isolated_execution_state"
|
|
4
|
+
|
|
5
|
+
module DataShifter
|
|
6
|
+
module Internal
|
|
7
|
+
# Tracks whether Axn's on_error path already printed failure context (summary).
|
|
8
|
+
# Used by rake tasks to avoid duplicating setup failure output.
|
|
9
|
+
module RakeExceptionReporting
|
|
10
|
+
KEY = :data_shifter_rake_failure_summary_reported
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def clear!
|
|
15
|
+
ActiveSupport::IsolatedExecutionState.delete(KEY)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def mark_failure_summary_reported!
|
|
19
|
+
ActiveSupport::IsolatedExecutionState[KEY] = true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def failure_summary_reported?
|
|
23
|
+
ActiveSupport::IsolatedExecutionState[KEY] == true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pathname"
|
|
4
|
+
|
|
5
|
+
require_relative "colors"
|
|
6
|
+
|
|
7
|
+
module DataShifter
|
|
8
|
+
module Internal
|
|
9
|
+
# Formatted stderr output when a rake data:shift task fails before the shift summary (load, constantize, etc.).
|
|
10
|
+
module RakeSetupOutput
|
|
11
|
+
extend self
|
|
12
|
+
|
|
13
|
+
BACKTRACE_LIMIT = 12
|
|
14
|
+
DIVIDER = "=" * 60
|
|
15
|
+
SEPARATOR = "-" * 60
|
|
16
|
+
|
|
17
|
+
def print_failure(io:, exception:, file_path:, task_name:)
|
|
18
|
+
lines = filtered_backtrace(exception, file_path)
|
|
19
|
+
display = relative_display_path(file_path)
|
|
20
|
+
|
|
21
|
+
io.puts ""
|
|
22
|
+
io.puts Colors.red(DIVIDER, io:)
|
|
23
|
+
io.puts Colors.error("DATA SHIFT SETUP FAILED", io:)
|
|
24
|
+
io.puts Colors.dim(SEPARATOR, io:)
|
|
25
|
+
io.puts "Rake task: data:shift:#{task_name}"
|
|
26
|
+
io.puts "File: #{display}"
|
|
27
|
+
io.puts Colors.dim(SEPARATOR, io:)
|
|
28
|
+
io.puts Colors.error("#{exception.class}: #{exception.message}", io:)
|
|
29
|
+
if lines.any?
|
|
30
|
+
io.puts ""
|
|
31
|
+
io.puts Colors.dim("Backtrace:", io:)
|
|
32
|
+
lines.each { |line| io.puts Colors.dim(" #{line}", io:) }
|
|
33
|
+
end
|
|
34
|
+
io.puts Colors.red(DIVIDER, io:)
|
|
35
|
+
io.puts ""
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def relative_display_path(file_path)
|
|
41
|
+
if defined?(Rails) && Rails.root
|
|
42
|
+
Pathname(file_path).relative_path_from(Rails.root).to_s
|
|
43
|
+
else
|
|
44
|
+
file_path.to_s
|
|
45
|
+
end
|
|
46
|
+
rescue ArgumentError
|
|
47
|
+
file_path.to_s
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def filtered_backtrace(exception, file_path)
|
|
51
|
+
raw = exception.backtrace || []
|
|
52
|
+
cleaned =
|
|
53
|
+
if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) && Rails.backtrace_cleaner
|
|
54
|
+
Rails.backtrace_cleaner.clean(raw)
|
|
55
|
+
else
|
|
56
|
+
raw
|
|
57
|
+
end
|
|
58
|
+
lines = cleaned.map(&:to_s).reject(&:empty?).first(BACKTRACE_LIMIT)
|
|
59
|
+
return lines if lines.any?
|
|
60
|
+
|
|
61
|
+
needle = file_path.to_s
|
|
62
|
+
lines = raw.select { |ln| ln.start_with?(needle) || ln.include?("/data_shifts/") }.first(BACKTRACE_LIMIT)
|
|
63
|
+
return lines if lines.any?
|
|
64
|
+
|
|
65
|
+
raw.first(BACKTRACE_LIMIT)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
data/lib/data_shifter/railtie.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "axn"
|
|
4
3
|
require "rails/railtie"
|
|
5
4
|
|
|
5
|
+
require_relative "internal/rake_setup_output"
|
|
6
|
+
|
|
6
7
|
module DataShifter
|
|
7
8
|
class Railtie < Rails::Railtie
|
|
8
9
|
# Extract description DSL from shift file without loading it.
|
|
@@ -67,12 +68,15 @@ module DataShifter
|
|
|
67
68
|
klass.run!
|
|
68
69
|
rescue Interrupt
|
|
69
70
|
exit(130)
|
|
70
|
-
rescue Axn::Failure
|
|
71
|
-
# run! re-raises after on_error :_print_summary; avoid Rake's duplicate backtrace.
|
|
72
|
-
exit(1)
|
|
73
71
|
rescue StandardError => e
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
unless Internal::RakeExceptionReporting.failure_summary_reported?
|
|
73
|
+
Internal::RakeSetupOutput.print_failure(
|
|
74
|
+
io: $stderr,
|
|
75
|
+
exception: e,
|
|
76
|
+
file_path:,
|
|
77
|
+
task_name:,
|
|
78
|
+
)
|
|
79
|
+
end
|
|
76
80
|
exit(1)
|
|
77
81
|
end
|
|
78
82
|
end
|
data/lib/data_shifter/shift.rb
CHANGED
|
@@ -59,7 +59,7 @@ module DataShifter
|
|
|
59
59
|
around :_with_transaction_for_dry_run
|
|
60
60
|
before :_reset_tracking
|
|
61
61
|
on_success :_print_summary
|
|
62
|
-
on_error :
|
|
62
|
+
on_error :_print_summary_for_axn_error
|
|
63
63
|
|
|
64
64
|
class_attribute :_transaction_mode, default: :single
|
|
65
65
|
class_attribute :_progress_enabled, default: nil
|
|
@@ -253,6 +253,7 @@ module DataShifter
|
|
|
253
253
|
end
|
|
254
254
|
|
|
255
255
|
def _reset_tracking
|
|
256
|
+
Internal::RakeExceptionReporting.clear!
|
|
256
257
|
@stats = { processed: 0, succeeded: 0, failed: 0, skipped: 0 }
|
|
257
258
|
@errors = []
|
|
258
259
|
@skip_reasons = Hash.new(0)
|
|
@@ -277,6 +278,11 @@ module DataShifter
|
|
|
277
278
|
)
|
|
278
279
|
end
|
|
279
280
|
|
|
281
|
+
def _print_summary_for_axn_error
|
|
282
|
+
_print_summary
|
|
283
|
+
Internal::RakeExceptionReporting.mark_failure_summary_reported!
|
|
284
|
+
end
|
|
285
|
+
|
|
280
286
|
# --- Override points ---
|
|
281
287
|
|
|
282
288
|
def collection
|
data/lib/data_shifter/version.rb
CHANGED
data/lib/data_shifter.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "data_shifter/version"
|
|
4
4
|
require_relative "data_shifter/configuration"
|
|
5
5
|
require_relative "data_shifter/errors"
|
|
6
|
+
require_relative "data_shifter/internal/rake_exception_reporting"
|
|
6
7
|
require_relative "data_shifter/shift"
|
|
7
8
|
require_relative "data_shifter/railtie"
|
|
8
9
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: data_shifter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kali Donovan
|
|
@@ -121,6 +121,8 @@ files:
|
|
|
121
121
|
- lib/data_shifter/internal/log_deduplicator.rb
|
|
122
122
|
- lib/data_shifter/internal/output.rb
|
|
123
123
|
- lib/data_shifter/internal/progress_bar.rb
|
|
124
|
+
- lib/data_shifter/internal/rake_exception_reporting.rb
|
|
125
|
+
- lib/data_shifter/internal/rake_setup_output.rb
|
|
124
126
|
- lib/data_shifter/internal/record_utils.rb
|
|
125
127
|
- lib/data_shifter/internal/side_effect_guards.rb
|
|
126
128
|
- lib/data_shifter/internal/signal_handler.rb
|