5

(newbie alert)

Given the following error message, what's the quickest way to get to the source of the error:

08/Jul/2016:11:39:01 +0530 [Error#yesod-core] expected EPlain but got Nothing for: DerefBranch (DerefIdent (Ident "show")) (DerefString "abcdef") @(yesod_3MCr4WfhviiELXmo3fAaXL:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs:625:5)
GET /
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Status: 500 Internal Server Error 0.054158s

Handler/Home.hs:38:11:
    No instance for (Text.Julius.ToJavascript String)
      arising from a use of ‘Text.Julius.toJavascript’
    In the second argument of ‘(GHC.Base..)’, namely
      ‘Text.Julius.toJavascript’
    In the second argument of ‘(GHC.Base..)’, namely
      ‘(Text.Julius.unJavascript GHC.Base.. Text.Julius.toJavascript)’
    In the expression:
      Text.Shakespeare.EPlain
      GHC.Base..
        (Text.Julius.unJavascript GHC.Base.. Text.Julius.toJavascript)
Build failure, pausing...

I'm working with a simple scaffolded site (no DB) and have purposely messed up with homepage.julius. In this particular instance I know exactly what the error is, but how can one know just by looking at the error message?

Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60

1 Answers1

2

After perusing http://hackage.haskell.org/package/shakespeare-2.0.8/docs/Text-Julius.html, it looks like you are trying to embed a plain string in something that wants javascript.

That is usually prevented so that someone can't inject bad code into a page when you are trying to just display a string they've supplied. So just call rawJS on it and it should embed? Or perhaps you are using the wrong interpolation type for the variable you are supplying (@,^, or #). Yesod is particular about that.

This just just a guess as I don't use julius.

David McHealy
  • 2,471
  • 18
  • 34
  • You are correct. That's what I was trying to do. However, my question is different. Looking at the error message, how does one get to know the exact line in the julius/cassius/hamlet template which is causing the error? – Saurabh Nanda Jul 08 '16 at 16:51
  • There is an option to dump template haskell splices during compile, which is something. But beyond that the source of the error is always going to be the line in your code where you called it. This is the reason I don't use templates, personally. – David McHealy Jul 08 '16 at 19:59
  • It doesn't solve this question, but Template Haskell can emit line pragmas in order to produce more useful error messages. I just don't think this template system is bothering with that. – glguy Aug 11 '16 at 08:00