{"record":{"id":"c892fd9a929304e5","repo":"phacility/phabricator","slug":"template-s-is-not-a-valid-template","errorCode":null,"errorMessage":"Template \"%s\" is not a valid template.","messagePattern":"Template \"(.+?)\" is not a valid template\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/macro/engine/PhabricatorMemeEngine.php","lineNumber":67,"sourceCode":"  public function getGenerateURI() {\n    $params = array(\n      'macro' => $this->getTemplate(),\n      'above' => $this->getAboveText(),\n      'below' => $this->getBelowText(),\n    );\n\n    return new PhutilURI('/macro/meme/', $params);\n  }\n\n  public function newAsset() {\n    $cache = $this->loadCachedFile();\n    if ($cache) {\n      return $cache;\n    }\n\n    $template = $this->loadTemplateFile();\n    if (!$template) {\n      throw new Exception(\n        pht(\n          'Template \"%s\" is not a valid template.',\n          $template));\n    }\n\n    $hash = $this->newTransformHash();\n\n    $asset = $this->newAssetFile($template);\n\n    $xfile = id(new PhabricatorTransformedFile())\n      ->setOriginalPHID($template->getPHID())\n      ->setTransformedPHID($asset->getPHID())\n      ->setTransform($hash);\n\n    try {\n      $caught = null;\n\n      $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/engine/PhabricatorMemeEngine.php#L49-L85","documentation":"PhabricatorMemeEngine::newAsset() renders a meme by first loading the template image via loadTemplateFile(); when that returns nothing (no macro/template file for the configured template name) it throws this exception. Note the interpolation passes the falsy $template, so the message renders as 'Template \"\" is not a valid template.' -- the useful information is which template name was set on the engine, not the interpolated value.","triggerScenarios":"Requesting /macro/meme/ (or calling the meme engine) with a template name whose underlying template file/macro does not exist: template macro deleted after being referenced, name typo, or a fresh install missing default macro images.","commonSituations":"Custom meme templates removed or renamed; bookmarks/links embedding an old template name; macro images garbage collected or pruned.","solutions":["Open the Macro application and confirm a macro exists for the template name; use its exact name.","Re-upload the missing template macro if it was deleted.","If you control the call site, verify the template resolves before invoking newAsset() (see exampleFix)."],"exampleFix":"// before\n$engine = id(new PhabricatorMemeEngine())\n  ->setTemplateByName('nonexistent_template')\n  ->setTopText('hi');\n$asset = $engine->newAsset(); // throws\n// after\n$engine = id(new PhabricatorMemeEngine())\n  ->setTemplateByName($valid_macro_name)\n  ->setTopText('hi');\n$asset = $engine->newAsset();\n// guard before rendering when template comes from user input:\nif (!$macro) {\n  return $this->newDialog()->setTitle(pht('Unknown Template'));\n}","handlingStrategy":"validation","validationCode":"// Verify the template resolves before rendering a meme:\n$template = $engine->loadTemplateFile();\nif (!$template) {\n  return new Aphront404Response(); // or render 'unknown template' dialog\n}\n$asset = $engine->newAsset();","typeGuard":"function memeTemplateExists($template_name) {\n  $macro = id(new PhabricatorFileQuery())\n    ->setViewer(PhabricatorUser::getOmnipotentUser())\n    ->withNames(array($template_name))\n    ->executeOne();\n  return (bool)$macro;\n}","tryCatchPattern":"try {\n  $asset = $engine->newAsset();\n} catch (Exception $ex) {\n  // template macro missing (deleted or never uploaded); degrade gracefully\n  return $this->newDialog()->setTitle(pht('Unknown Meme Template'));\n}","preventionTips":["Validate the template name against existing macros when accepting user input for memes.","Do not delete macro images still referenced as meme templates; check references first.","Note the exception message interpolates the falsy template value, so log the engine's configured name for debugging."],"tags":["macro","meme","phabricator","image-template","file"],"backgroundTag":"missing-template-file","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}