Show a warning message when the attachments URL are 404#16087
Show a warning message when the attachments URL are 404#16087
Conversation
📝 WalkthroughWalkthroughAdds robust remote-attachment error handling to assemblies and participatory_processes importers: validates URLs, replaces existence checks with a remote_file_error flow, wraps downloads in rescue blocks, normalizes error messages via format_error, and adds attachment_title for display; translations and tests updated accordingly. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@decidim-assemblies/app/serializers/decidim/assemblies/assembly_importer.rb`:
- Around line 87-96: The rescue block around URI.parse(url).open in the assembly
importer should also handle Errno::ECONNREFUSED to mirror the error handling in
import_hero_image and import_banner_image; update the rescue clause that
currently catches OpenURI::HTTPError, Errno::ENOENT, SocketError,
Net::OpenTimeout, Net::ReadTimeout to include Errno::ECONNREFUSED so
connection-refused errors are captured, add the same error variable (e) usage in
the I18n warning message, and ensure this change is applied in the method where
file_tmp is assigned (the URI.open block in the
AssemblyImporter/assembly_importer.rb).
In
`@decidim-participatory_processes/app/serializers/decidim/participatory_processes/participatory_process_importer.rb`:
- Around line 109-118: The rescue block that handles download errors in
ParticipatoryProcessImporter (the block using URI.parse(url).open) is missing
Errno::ECONNREFUSED and can crash on connection-refused; update that rescue
clause to also catch Errno::ECONNREFUSED (matching the other methods
import_hero_image and import_group_hero_image) and ensure the same warning is
pushed into `@warnings` using e.message so connection-refused errors are handled
gracefully.
🧹 Nitpick comments (1)
decidim-assemblies/app/serializers/decidim/assemblies/assembly_importer.rb (1)
71-121: Significant code duplication withParticipatoryProcessImporter.
import_folders_and_attachments,remote_file_exists?, andattachment_titleare identical (modulo@imported_assemblyvs@imported_processand the I18n key namespace) acrossAssemblyImporterandParticipatoryProcessImporter. Consider extracting shared attachment-import logic into a concern or the baseDecidim::Importers::Importerclass to reduce duplication and ensure future fixes apply to both modules.Also applies to: 160-167
decidim-assemblies/app/serializers/decidim/assemblies/assembly_importer.rb
Show resolved
Hide resolved
..._processes/app/serializers/decidim/participatory_processes/participatory_process_importer.rb
Show resolved
Hide resolved
536eb16
|
This is ready for the review @alecslupu |

🎩 What? Why?
As I mentioned in #16026, I found yet another bug in the import spaces flow. This is basically the same as the one in #16026, but this time with attachments: if the attachments don't exist, then we have an exception during the import process.
The proposed solution is by adding more warnings about this, so the admin can fix it afterwards.
📌 Related Issues
Testing
This is the assembly that I'm using for my local exploration:
assemblies-bad.json
Stacktrace
📷 Screenshots
Before
After
Summary by CodeRabbit
Bug Fixes
Documentation
Tests