Skip to content

Commit

Permalink
Find dirconfig error before it causes issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Nov 25, 2024
1 parent 4c19693 commit db823d4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def process_activities
dirs = activity_dirs
errors = []

# Read all config files and dirconfig files in the activity directories
# filter out the invalid ones and keep track of them to make a single error report at the end
activity_dirs_and_configs = dirs.map do |d|
Pathname.new('./').join(activity_relative_path(d)).parent.descend.each do |p|
read_config_file(full_path.join(p, Activity::DIRCONFIG_FILE))
Expand All @@ -146,6 +148,15 @@ def process_activities
nil
end.compact

# Read the outermost dirconfig file
# if it contains errors, don't process any activities
begin
read_config_file(full_path.join(Activity::DIRCONFIG_FILE))

Check warning on line 154 in app/models/repository.rb

View check run for this annotation

Codecov / codecov/patch

app/models/repository.rb#L154

Added line #L154 was not covered by tests
rescue ConfigParseError => e
errors.push e
raise AggregatedConfigErrors.new(self, errors)

Check warning on line 157 in app/models/repository.rb

View check run for this annotation

Codecov / codecov/patch

app/models/repository.rb#L156-L157

Added lines #L156 - L157 were not covered by tests
end

existing_activities = activity_dirs_and_configs
.reject { |_, c| c['internals'].nil? || c['internals']['token'].nil? }
.map { |d, c| [d, Activity.find_by(repository_token: c['internals']['token'], repository_id: id)] }
Expand Down Expand Up @@ -274,10 +285,6 @@ def update_activity(act)
end

act.save
rescue ConfigParseError => e
# Add error to the list of errors encountered during processing
# This way the error will be picked up and aggregated in the process_activities method
errors.push e
end

def github_url(path = nil, mode: nil)
Expand Down

0 comments on commit db823d4

Please sign in to comment.