Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 13, 2025

Problem

When creating content using the "Create content" button with a content type that has a template defined, the template was not being applied. This occurred because template loading errors were not properly handled, causing the content creation process to fail silently and fall back to creating content without the template.

Root Cause

The ArticleHelper.getContents() method did not have proper error handling around workspace.fs.readFile(). When a template file doesn't exist or can't be read, this method throws an error that bubbles up and causes the template loading to fail silently.

Solution

Added comprehensive error handling to ensure template loading errors are handled gracefully:

  1. Added try-catch in ArticleHelper.getContents() - Prevents file reading errors from crashing the process
  2. Added try-catch around template loading in ContentType.create() - Provides specific error handling for content type templates
  3. Added user notifications - Users now receive clear feedback when template loading fails
  4. Added debug logging - Better troubleshooting capabilities for developers

Example

Before this fix:

{
  "name": "project",
  "template": "[[workspace]]/.frontmatter/templates/project.md"
}

If project.md doesn't exist → Silent failure, no template applied, no user feedback

After this fix:

  • If template exists → Loads and applies correctly ✅
  • If template missing → Shows error notification, continues content creation without template ✅
  • If template malformed → Shows error notification, continues content creation without template ✅

Impact

  • No regressions: Valid templates continue to work exactly as before
  • Better resilience: Invalid templates no longer crash content creation
  • Improved UX: Users get clear error messages instead of silent failures
  • Better debugging: Detailed logging helps identify template issues

Fixes #950.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Issue: Template is not applied to new content type when created Fix template loading error handling for content types Jun 13, 2025
@Copilot Copilot AI requested a review from estruyf June 13, 2025 13:30
Copilot finished work on behalf of estruyf June 13, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Template is not applied to new content type when created

2 participants