Page MenuHomePhabricator

TypeError when editing calendar import
Closed, ResolvedPublic

Description

Editing a calendar import (e.g. by visiting /calendar/import/edit/1/) causes the following exception:

EXCEPTION: (TypeError) PhabricatorCalendarImport::initializeNewCalendarImport(): Argument #2 ($engine) must be of type PhabricatorCalendarImportEngine, null given, called in .../phabricator/src/applications/calendar/editor/PhabricatorCalendarImportEditEngine.php on line 44 at [<phabricator>/src/applications/calendar/storage/PhabricatorCalendarImport.php:26]
arcanist(head=master, ref.master=82016c00e132), phabricator(head=master, ref.master=8daaf5ef2145)
  #0 phlog(TypeError) called at [<phabricator>/src/aphront/handler/PhabricatorDefaultRequestExceptionHandler.php:41]
  #1 PhabricatorDefaultRequestExceptionHandler::handleRequestThrowable(AphrontRequest, TypeError) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:751]
  #2 AphrontApplicationConfiguration::handleThrowable(TypeError) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:296]
  #3 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:204]
  #4 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phabricator>/webroot/index.php:35]
DepthLibraryFileWhere
10phabricatorapplications/calendar/editor/PhabricatorCalendarImportEditEngine.php44PhabricatorCalendarImport::initializeNewCalendarImport()
9phabricatorapplications/transactions/editengine/PhabricatorEditEngine.php228PhabricatorCalendarImportEditEngine::newEditableObject()
8phabricatorapplications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php24PhabricatorEditEngine::supportsSubtypes()
7phabricatorapplications/transactions/editengine/PhabricatorEditEngine.php184PhabricatorSubtypeEditEngineExtension::supportsObject()
6phabricatorapplications/transactions/editengine/PhabricatorEditEngine.php1036PhabricatorEditEngine::buildEditFields()
5phabricatorapplications/transactions/editengine/PhabricatorEditEngine.php998PhabricatorEditEngine::buildEditResponse()
4phabricatorapplications/calendar/controller/PhabricatorCalendarImportEditController.php27PhabricatorEditEngine::buildResponse()
3phabricatoraphront/configuration/AphrontApplicationConfiguration.php284PhabricatorCalendarImportEditController::handleRequest()
2phabricatoraphront/configuration/AphrontApplicationConfiguration.php204AphrontApplicationConfiguration::processRequest()
1.../phabricator/webroot/index.php35AphrontApplicationConfiguration::runHTTPRequest()

The import engine is not set in frame 4, so it's null in the call to initializeNewCalendarImport in frame 10. This is frowned upon.

Possible solutions:

  1. Catch Error (or Throwable) in PhabricatorEditEngine. Since TypeError is not a subtype of Exception, it's not currently caught.
  2. If there is no import engine, throw an exception in PhabricatorCalendarImportEditEngine before initializing the import. This sort of thing happens in AlmanacService.
  3. Attach the import engine in PhabricatorCalendarImportEditEngine after initializing the import, rather than in PhabricatorCalendarImport. Prior art in DrydockBlueprintEditEngine.

Event Timeline

I think this is probably the cleanest fix, but I only tested event imports (which now appear to work). If you want to test Maniphest with subtypes configured (to make sure it doesn't break) and send me a revision with this change, I'll review it. Otherwise, I'll do that testing when I get a chance and land this if nothing crops up.

diff --git a/src/applications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php b/src/applications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php
index e73d476d74..3a301d8410 100644
--- a/src/applications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php
+++ b/src/applications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php
@@ -21,7 +21,7 @@ final class PhabricatorSubtypeEditEngineExtension
   public function supportsObject(
     PhabricatorEditEngine $engine,
     PhabricatorApplicationTransactionInterface $object) {
-    return $engine->supportsSubtypes();
+    return ($object instanceof PhabricatorEditEngineSubtypeInterface);
   }
 
   public function buildCustomEditFields(