-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add update_activity errors to aggregated errors for mailing #5958
Conversation
WalkthroughThe changes in this pull request focus on enhancing error handling within the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Repository
participant ConfigParser
User->>Repository: process_activities()
Repository->>ConfigParser: read outermost config
alt ConfigParseError
ConfigParser-->>Repository: raise ConfigParseError
Repository->>Repository: push error to errors array
Repository-->>User: report errors
else No Error
Repository->>ConfigParser: read activity configs
Repository-->>User: process activities
end
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
app/models/repository.rb
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
app/models/repository.rb
[warning] 279-279: app/models/repository.rb#L279
Added line #L279 was not covered by tests
🔇 Additional comments (3)
app/models/repository.rb (3)
277-279
: LGTM: Error handling approach
The approach of collecting ConfigParseError in the errors array aligns well with the PR objective of aggregating errors for mailing. This maintains consistency with the error handling pattern used in process_activities.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 279-279: app/models/repository.rb#L279
Added line #L279 was not covered by tests
277-279
: Add test coverage for error handling
The error handling code lacks test coverage. Please add tests to verify the behavior when ConfigParseError is raised.
Let's check for existing tests:
Would you like me to help generate test cases for the error handling scenarios?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 279-279: app/models/repository.rb#L279
Added line #L279 was not covered by tests
277-279
: Verify integration with process_activities
The error handling integrates with process_activities, but let's verify all call sites properly handle the errors array.
✅ Verification successful
Let me gather more information about how these errors are handled and propagated.
Based on the comprehensive analysis of the code, I can now provide the final response:
Error handling integration is properly implemented
The error handling in the update_activity
method is correctly integrated with the process_activities
workflow:
- Errors from ConfigParseError are collected in the errors array
- The errors array is checked at the end of process_activities and raises AggregatedConfigErrors if any errors exist
- AggregatedConfigErrors triggers email notifications through ErrorMailer as shown in the error rescue blocks
- The error collection and propagation path is complete and consistent
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check all calls to update_activity to ensure proper error handling
# Search for update_activity calls
rg -A 5 "update_activity" --type ruby
# Search for ConfigParseError handling
rg -A 5 "rescue.*ConfigParseError" --type ruby
Length of output: 2475
Script:
#!/bin/bash
# Check how errors are used in process_activities and related error handling
ast-grep --pattern 'def process_activities
$$$
end'
# Check for AggregatedConfigErrors usage
rg -B 5 -A 5 "AggregatedConfigErrors" --type ruby
# Check error handling in the Repository class
rg -B 3 -A 3 "errors\." --type ruby
Length of output: 36653
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 279-279: app/models/repository.rb#L279
Added line #L279 was not covered by tests
app/models/repository.rb
Outdated
rescue ConfigParseError => e | ||
# add error to the list of errors | ||
errors.push e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize the errors array before using it
The errors
array is being used but not initialized in the method scope. This could lead to undefined method 'push' for nil:NilClass errors.
Apply this diff to fix the issue:
def update_activity(act)
+ errors = []
config = act.merged_config
# ... rest of the method ...
rescue ConfigParseError => e
# add error to the list of errors
errors.push e
end
Additionally, consider passing the errors array as a parameter to make error collection more explicit:
- def update_activity(act)
+ def update_activity(act, errors = [])
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
rescue ConfigParseError => e | |
# add error to the list of errors | |
errors.push e | |
def update_activity(act, errors = []) | |
rescue ConfigParseError => e | |
# add error to the list of errors | |
errors.push e |
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 279-279: app/models/repository.rb#L279
Added line #L279 was not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
app/models/repository.rb (2)
Line range hint
139-150
: Consider extracting directory traversal logic to improve readabilityThe nested directory traversal and config file reading logic is complex. Consider extracting it into a separate method for better maintainability.
def process_activities dirs = activity_dirs errors = [] - 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)) - end - [d, read_config_file(Activity.config_file(d))] - rescue ConfigParseError => e - errors.push e - nil - end.compact + activity_dirs_and_configs = process_directory_configs(dirs, errors) + private + + def process_directory_configs(dirs, errors) + dirs.map do |d| + process_single_directory_config(d, errors) + end.compact + end + + def process_single_directory_config(dir, errors) + Pathname.new('./').join(activity_relative_path(dir)).parent.descend.each do |p| + read_config_file(full_path.join(p, Activity::DIRCONFIG_FILE)) + end + [dir, read_config_file(Activity.config_file(dir))] + rescue ConfigParseError => e + errors.push e + nil + end
163-167
: Remove unnecessary Rubocop directiveThe Rubocop disable directive for
Style/CollectionCompact
is redundant and can be removed.- # rubocop:disable Style/CollectionCompact - # This is a false positive for Hash#compact, where this is Array#compact .reject { |_, a| a.nil? } - # rubocop:enable Style/CollectionCompactAdditionally, consider using
compact
instead ofreject { |_, a| a.nil? }
for better readability:- .reject { |_, a| a.nil? } + .compact🧰 Tools
🪛 rubocop (1.67.0)
[warning] 163-163: Unnecessary disabling of
Style/CollectionCompact
.(Lint/RedundantCopDisableDirective)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
app/models/repository.rb
(2 hunks)
🧰 Additional context used
🪛 rubocop (1.67.0)
app/models/repository.rb
[warning] 163-163: Unnecessary disabling of Style/CollectionCompact
.
(Lint/RedundantCopDisableDirective)
🔇 Additional comments (2)
app/models/repository.rb (2)
151-158
: LGTM! Good error handling for the outermost dirconfig
The implementation correctly prevents further activity processing when the outermost dirconfig has errors, which addresses the PR objective of properly handling configuration parser errors.
Line range hint 139-158
: Verify error handling coverage
Let's ensure all error paths are properly covered and errors are consistently collected.
✅ Verification successful
Let me gather more context about the error handling implementation.
Error handling implementation is robust and well-structured
The error handling implementation shows a comprehensive approach:
- ConfigParseError exceptions are consistently caught and collected in both repository and activity processing
- Errors are uniquely aggregated by path in AggregatedConfigErrors
- The Activity class properly validates configs by catching parse errors
- Error collection is centralized and leads to a single aggregated error report
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for potential error handling gaps
# Check for ConfigParseError rescue blocks
echo "Checking ConfigParseError handling coverage:"
rg -A 2 "rescue ConfigParseError"
# Check for error collection points
echo "\nChecking error collection points:"
rg "errors\.push"
# Check for error aggregation
echo "\nChecking error aggregation:"
rg "AggregatedConfigErrors"
Length of output: 1317
Script:
#!/bin/bash
# Check the AggregatedConfigErrors implementation
echo "Checking AggregatedConfigErrors implementation:"
cat app/models/transient/aggregated_config_errors.rb
# Check the full context of error handling in repository.rb
echo "\nChecking repository.rb error handling context:"
rg -B 5 -A 5 "errors\s*=" app/models/repository.rb
# Check Activity class error handling
echo "\nChecking Activity class error handling:"
rg -B 3 -A 3 "ConfigParseError" app/models/activity.rb
Length of output: 1256
🧰 Tools
🪛 rubocop (1.67.0)
[warning] 163-163: Unnecessary disabling of Style/CollectionCompact
.
(Lint/RedundantCopDisableDirective)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.
This pull request fixes a config parser error email not being sent when the error was in the outer
dirconfig.json
Also renamed some variables from
e(xercise)
toa(ctivity)
to please robocop variable reuse issues with thee(rror)
variable