Document Creator 0.2.8: Named errors, safer thumbnails and guarded buttons
Document Creator 0.2.8 makes the admin pages sturdier and the module’s errors easier to handle. Errors from Google Drive are now named reasons instead of raw API text, and a new Errors.message/1 turns each into a translated message.
Thumbnails are only fetched from Google’s own hosts, and redirects are not followed, so a crafted thumbnail address cannot make the server call an internal address. Every button that starts a slow or destructive action, such as creating, exporting, restoring or deleting, is disabled while it runs, so a double click no longer starts it twice. A failed action is now also recorded in the activity log, and a Drive error during a file action no longer crashes the page. Opening a folder with many files fetches at most eight thumbnails at a time.
Names longer than 255 characters now return a validation error instead of a database error.
Upgrading
Code that matched the old error strings from GoogleDocsClient must match the new atoms, or show them with PhoenixKitDocumentCreator.Errors.message/1.
Full release notes: Document Creator 0.2.8
0.2.8 · 30 April 2026
Added
PhoenixKitDocumentCreator.Errors— atom dispatcher with one literalgettext/1clause per atom (28 atoms). Centralises error translation for the public API; consumers callErrors.message(reason)at the UI/API boundary. Same shape asPhoenixKitSync.ErrorsandPhoenixKitLocations.Errors. Documented in README.- SSRF guard on
GoogleDocsClient.fetch_thumbnail_image/1—validate_thumbnail_url/1allowlists*.googleusercontent.com/*.google.comhost suffixes; rejects metadata service (169.254.169.254), loopback, RFC1918, look-alike hosts, non-http(s)schemes. Pinned with 8 unit tests. - Redirect block on the thumbnail fetch —
Req.get/2is called withredirect: falseso a 302 from a Google CDN host to an internal IP can’t bypass the SSRF allowlist. Pinned with aReq.Test-stubbed end-to-end test. - LiveView test infrastructure:
Test.Endpoint,Test.Router,Test.Layouts(with stable flash IDs),LiveCase, on-mount hooks,ActivityLogAssertionshelper,Test.StubIntegrationsETS-backed integrations stub. phx-disable-withon every async + destructive button (refresh, create, modal create, file actions, export PDF, restore, delete, save folder settings, unfiled actions).- AGENTS.md “What This Module Does NOT Have (by design)” section anchoring deliberate non-features.
Changed
- (potentially breaking)
GoogleDocsClientandDriveWalkernow return tagged atoms (:folder_search_failed,:create_folder_failed,:create_document_failed,:move_failed,:get_file_parents_failed,:copy_failed,:pdf_export_failed,:thumbnail_link_failed,:thumbnail_fetch_failed,:list_files_failed) on the error branch instead of raw{:error, "Foo failed: #{inspect(body)}"}strings. Consumers matching on the string form must switch to atoms (or callErrors.message/1to translate). Document.creation_changeset/2,Document.sync_changeset/2, andTemplate.sync_changeset/2nowvalidate_length(:name, max: 255). Over-long names return a clean{:error, %Ecto.Changeset{}}instead of raisingEcto.Adapters.SQLexceptions.Documents.fetch_thumbnails_async/2runs under a single supervised parent task inPhoenixKit.TaskSupervisorwithTask.async_stream/3max_concurrency: 8. Pre-fix opening a 500-file folder fired 500 unsupervisedTask.start/1calls.DocumentsLive.mount/3subscribes to"document_creator:files"BEFORE the initial DB read, closing a race window where a:files_changedbroadcast could be dropped between read and subscribe.- Activity logging now lands a
db_pending: trueaudit row on the error branch of every user-driven mutation (create_template,create_document,delete_*,restore_*,export_pdf,set_correct_location,create_document_from_template). Pre-fix a Drive outage erased admin clicks from the audit feed. Task.start/1→Task.start_link/1in:sync_from_driveand:load_drive_foldersLV handlers — orphan tasks now die with the LV instead of running unsupervised after the tab closes.try/rescuearound the:perform_file_actionbackend call so a Drive API raise (econnrefused, HTTP timeout) doesn’t crash the LV and wedgepending_fileson remount.- Drive API error responses are now logged at 500-char truncation via
log_drive_error/2instead of being serialised in full into the error tuple. discover_folders/0timeout cleanup now usescatch :exit, _instead ofrescue—Task.await_many/2signals timeouts viaexit/1, so the previousrescueclause never fired and the LV crashed instead of hitting the nil fallback.extract_content_type/1logs at:debugwhen a Drive thumbnail’s content-type falls outside the~w(image/png image/jpeg image/webp image/gif)allowlist and is downgraded toimage/png.handle_infocatch-all in both LiveViews promoted from silent drop toLogger.debugso stray PubSub / fixture messages stay observable when debugging.
Fixed
- Removed deprecated
Variable.extract_from_html/1(was@doc false+@deprecatedsince the Google Docs pivot). enabled?/0now addscatch :exit, _ -> falsefor sandbox-shutdown resilience.- README: new
PhoenixKitDocumentCreator.Errorssection listing the error atoms emitted by the public API and showing the canonical translate-at-the-boundary pattern.
Tests
- 161 → 376 tests, 0 failures, 10/10 stable runs.
- Production coverage: ~52% → 77.92% via built-in
mix test --cover(no Mox / no excoveralls).mix.exsaddstest_coverage: [ignore_modules: [...]]so the percentage reports production-only code.
Document Creator 0.2.8. Install or update: {:phoenix_kit_document_creator, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.