Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid front matter causes 500 server error #16624

Open
djuber opened this issue Feb 17, 2022 · 2 comments
Open

Invalid front matter causes 500 server error #16624

djuber opened this issue Feb 17, 2022 · 2 comments
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution external contributors welcome contribution is welcome!

Comments

@djuber
Copy link
Contributor

djuber commented Feb 17, 2022

Describe the bug

When I have the Basic Markdown editor (editor v1)
When creating a new post with this content (rather than hash keys, a plain string, in the frontmatter)

---
Text in the frontmatter?
---

Not a good idea

When I preview the post, I get a 500 server error (and no indication why).

To Reproduce
visit /settings/customization and confirm Basic Markdown Editor Version is selected
click Create Post
Erase the frontmatter template (title/ cover image, tags) and replace with a simple string.
Click the preview tab.

Expected behavior

Either the frontmatter delimiter dashes --- are treated as horizontal rules when no key-value pairs are provided, or an indication that the frontmatter is invalid is shown to the user.

Screenshots

Preview Error

Additional context

https://app.honeybadger.io/projects/66984/faults/84085022 (no method to_h for String at parsed.front_matter.to_h in ArticlesController#preview)

Started after #16569 fixed another error showing on article preview

@github-actions
Copy link
Contributor

Thanks for the issue, we will take it into consideration! Our team of engineers is busy working on many types of features, please give us time to get back to you.

Feature requests that require more discussion may be closed. Read more about our feature request process on forem.dev.

To our amazing contributors: issues labeled type: bug are always up for grabs, but for feature requests, please wait until we add a ready for dev before starting to work on it.

To claim an issue to work on, please leave a comment. If you've claimed the issue and need help, please ping @forem/oss. The OSS Community Manager or the engineers on OSS rotation will follow up.

For full info on how to contribute, please check out our contributors guide.

@citizen428
Copy link
Contributor

This problem seems to (partially) originate in Article#has_frontmatter?:

  def has_frontmatter?
    fixed_body_markdown = MarkdownProcessor::Fixer::FixAll.call(body_markdown)
    begin
      parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
      parsed.front_matter["title"].present?
    rescue Psych::SyntaxError, Psych::DisallowedClass
      # if frontmatter is invalid, still render editor with errors instead of 500ing
      true
    end
  end

BTW, when trying to post instead of previewing you'll see different errors:

Screen Shot 2022-02-21 at 11 29 45

@citizen428 citizen428 added area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution labels Feb 21, 2022
@PhilipHow PhilipHow added the external contributors welcome contribution is welcome! label Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution external contributors welcome contribution is welcome!
Projects
Development

No branches or pull requests

3 participants