Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine and minimise recovery warning output #141

Merged
merged 4 commits into from May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions ruby/docker/files/steps.rb
Expand Up @@ -12,17 +12,24 @@ def layers_for(group)
end

def steps_for(group)
step_precedence[group]&.map do |s|
begin
class_for('Steps', s)
rescue NameError => e
warn(error: e, klass: namespaced_name(namespace_for('Step'), s))
general_steps[s]
end.new(self)
step_precedence[group]&.map { |s| step_for(s) }&.compact
end

def step_for(symbol)
begin
class_for(step_concern, symbol).new(self)
rescue NameError
general_step_for(symbol)
end
end

def step_precedence; klass.step_precedence ;end
def general_step_for(symbol)
begin
general_class_for(step_concern, symbol)
rescue NameError => e
general_steps[symbol] || warn(error: e, name: namespaced_name(namespace_for(step_concern), symbol))
end&.new(self)
end

def general_steps
{
Expand All @@ -31,6 +38,9 @@ def general_steps
}
end

def step_precedence; klass.step_precedence ;end
def step_concern; 'Steps' ;end

end
end
end
2 changes: 1 addition & 1 deletion ruby/frameworks/steps/final.rb
@@ -1,4 +1,4 @@
require_relative 'requires'
require_relative '../../docker/files/step'

module Frameworks
module Steps
Expand Down
1 change: 0 additions & 1 deletion ruby/frameworks/steps/requires.rb

This file was deleted.

26 changes: 17 additions & 9 deletions ruby/images/scripts.rb
Expand Up @@ -5,20 +5,28 @@ module Scripts
include Spaces::Constantizing

def scripts
script_lot&.map do |s|
class_for('Scripts', s).new(self)
rescue NameError => e
warn(error: e, klass: namespaced_name(namespace_for('Scripts'), s))
end
script_lot&.map { |s| script_for(s) }
end

def script_lot
klass.script_lot
def script_for(symbol)
begin
class_for(script_concern, symbol).new(self)
rescue NameError
general_script_for(symbol)
end
end

def script_path
'scripts'
def general_script_for(symbol)
begin
general_class_for(script_concern, symbol)
rescue NameError => e
warn(error: e, name: namespaced_name(namespace_for(script_concern), symbol))
end&.new(self)
end

def script_lot; klass.script_lot ;end
def script_concern; 'Scripts' ;end
def script_path; 'scripts' ;end

end
end
2 changes: 1 addition & 1 deletion ruby/nodules/pear/scripts/preparation.rb
@@ -1,4 +1,4 @@
require_relative 'requires'
require_relative '../../../texts/one_time_script'

module Nodules
module Pear
Expand Down
1 change: 0 additions & 1 deletion ruby/nodules/pear/scripts/requires.rb

This file was deleted.

78 changes: 25 additions & 53 deletions ruby/recovery/i18n/en.yaml
@@ -1,56 +1,28 @@
en:
trace:

blueprints::space/each:
blueprints::space/block_in_import_anchors_for:
blueprints::space/import:
git::space/import:
An attempt to import blueprint for %{descriptor} finds it already exists. Moving on.

docker::files::steps/block_in_steps_for:
spaces::constantizing/class_for:
spaces::constantizing/rescue_in_class_for:
spaces::constantizing/const_get:
Unable to find %{klass}. Attempting to look it up in general step map.

docker::files::steps/map:
docker::files::steps/block_in_steps_for:
spaces::constantizing/class_for:
spaces::constantizing/const_get:
Unable to find class %{name}. Attempting to substitute %{generalisation}.

images::scripts/scripts:
images::scripts/map:
images::scripts/block_in_scripts:
spaces::constantizing/class_for:
Unable to find class %{name}. Attempting to substitute %{generalisation}.

images::scripts/block_in_scripts:
spaces::constantizing/class_for:
spaces::constantizing/rescue_in_class_for:
spaces::constantizing/const_get:
Unable to find %{klass}.

images::scripts/map:
images::scripts/block_in_scripts:
spaces::constantizing/class_for:
spaces::constantizing/const_get:
Unable to find class %{name}. Attempting to substitute %{generalisation}.

releases::division/map:
releases::division/block_in_all:
releases::division/subdivision_for:
releases::division/subdivision_class:
There is no subdivision class defined for %{klass}. Substituting OpenStruct.

spaces::space/by_yaml:
spaces::space/_by:
spaces::space/open:
spaces::space/initialize:
An instance of %{klass} for %{descriptor} does not exist in its space.

texts::text/resolution:
texts::text/with_resolved_infixes:
texts::text/map:
texts::infix/resolution:
Unable to resolve text infix for %{value} in %{text}.
blueprints::space/import:
git::space/import: |
An attempt to import blueprint for %{descriptor} finds it already exists.
Moving on.

docker::files::steps/rescue_in_step_for:
docker::files::steps/general_step_for:
Unable to find class %{name}.

images::scripts/rescue_in_script_for:
images::scripts/general_script_for:
Unable to find class %{name}.

releases::division/check_subdivision_class:
releases::division/subdivision_class: |
There is no subdivision class defined for %{klass}.
Substituting OpenStruct.

spaces::space/open:
spaces::space/initialize:
An instance of %{klass} for %{descriptor} does not yet exist in its space.

texts::text/map:
texts::infix/resolution:
Unable to resolve text infix for %{value} in %{text}.
6 changes: 3 additions & 3 deletions ruby/recovery/trace.rb
Expand Up @@ -9,7 +9,7 @@ class Trace < ::Spaces::Thing
:witnesses,
:verbosity

def t(id = identifier); super(id, witnesses) ;end
def t(id = identifier); super(id, **witnesses) ;end

def spout_trace
if verbosity&.include?(:trace)
Expand Down Expand Up @@ -40,8 +40,8 @@ def array
@array ||= (error&.backtrace || []).select do |s|
s.include? 'Spaces' # FIX: will fail if project name changes
end.reject do |s|
s.include? 'method_missing'
end.take(4).reverse.map(&:shortened_trace_line)
s.include?('method_missing') || s.include?('spaces/constantizing')
end.take(2).reverse.map(&:shortened_trace_line)
end

def initialize(args)
Expand Down
8 changes: 7 additions & 1 deletion ruby/releases/division.rb
Expand Up @@ -26,7 +26,6 @@ def all
def subdivision_for(struct)
subdivision_class.new(struct: struct, division: self)
rescue NameError => e
warn(error: e, klass: klass)
struct
end

Expand All @@ -36,11 +35,18 @@ def release_path; "#{super}/#{label}" ;end
def memento; all&.map(&:memento) || super ;end

def initialize(struct: nil, stage: nil, label: nil)
check_subdivision_class
self.stage = stage
self.label = label
self.struct = struct || stage&.struct[label] || default
end

def check_subdivision_class
subdivision_class
rescue NameError => e
warn(error: e, klass: klass)
end

def default ;end

end
Expand Down
15 changes: 6 additions & 9 deletions ruby/spaces/constantizing.rb
Expand Up @@ -2,21 +2,18 @@ module Spaces
module Constantizing

def class_for(concern, symbol)
n = namespaced_name(namespace_for(concern), symbol)
gn = namespaced_name(generalised_namespace_for(concern), symbol)

Module.const_get(n)

rescue NameError => e
warn(error: e, name: n, generalisation: gn)
Module.const_get(namespaced_name(generalised_namespace_for(concern), symbol))
Module.const_get(namespaced_name(namespace_for(concern), symbol))
end

def namespace_for(concern)
[self.class.name.split('::')[0 .. -2], concern].flatten.join('::')
end

def generalised_namespace_for(concern)
def general_class_for(concern, symbol)
Module.const_get(namespaced_name(general_namespace_for(concern), symbol))
end

def general_namespace_for(concern)
[self.class.name.split('::').first, concern].join('::')
end

Expand Down