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

Malformed json being produced when doc comment has quotes. #62

Closed
bsermons opened this issue Aug 26, 2015 · 6 comments
Closed

Malformed json being produced when doc comment has quotes. #62

bsermons opened this issue Aug 26, 2015 · 6 comments
Labels

Comments

@bsermons
Copy link

I keep getting a malformed json error with the following code snippet when I put the cursor at SqlCommandProvider. Once the error happens, fsharp-mode becomes useless as the status window is out of control. Not sure if this is an FsAutoComplete issue or a Newtonsoft issue as to which is outputting the malformed json so posting here until I can dig deeper.

module FSharpErrorTest

open System
open FSharp.Data
open FSharp.Data.SqlClient

[<Literal>]
let connectionString =
  @"Data Source=localhost;User Id=user; password=Test123;Initial Catalog=testdb;MultipleActiveResultSets=True"

type GetProject =
  SqlCommandProvider<"SELECT * FROM Projects WHERE Id = @id", connectionString>

let getProjectById id =
  use cmd = new SqlCommandProvider<"SELECT * FROM Projects WHERE Id=@id", connectionString>

  cmd.Execute(id)
  |> Seq.map (fun x -> x.Title)

from Messages buffer

error in process filter: Wrong type argument: hash-table-p, "Error: F# completion process produced malformed JSON ({\"Kind\":\"tooltip\",\"Data\":\"type SqlCommandProvider\\n\\nFull name: FSharp.Data.SqlCommandProvider\\n\\n\\n\\n<summary>Typed representation of a T-SQL statement to execute against a SQL Server database.</summary> \\n<param name='CommandText'>Transact-SQL statement to execute at the data source.</param>\\n<param name='ConnectionStringOrName'>String used to open a SQL Server database or the name of the connection string in the configuration file in the form of \"name=&lt;connection string name&gt;\".</param>\\n<param name='ResultType'>A value that defines structure of result: Records, Tuples, DataTable, or SqlDataReader.</param>\\n<param name='SingleRow'>If set the query is expected to return a single row of the result set. See MSDN documentation for details on CommandBehavior.SingleRow.</param>\\n<param name='ConfigFile'>The name of the configuration file that's used for connection strings at DESIGN-TIME. The default value is app.config or web.config.</param>\\n<param name='AllParametersOptional'>If set all parameters become optional. NULL input values must be handled inside T-SQL.</param>\\n<param name='ResolutionFolder'>A folder to be used to resolve relative file paths to *.sql script files at compile time. The default value is the folder that contains the project or script.</param>\\n<param name='DataDirectory'>The name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.</param>\"}

from fsharp-complete buffer:

{"Kind":"tooltip","Data":"type SqlCommandProvider\n\nFull name: FSharp.Data.SqlCommandProvider\n\n\n\n<summary>Typed representation of a T-SQL statement to execute against a SQL Server database.</summary> \n<param name='CommandText'>Transact-SQL statement to execute at the data source.</param>\n<param name='ConnectionStringOrName'>String used to open a SQL Server database or the name of the connection string in the configuration file in the form of "name=&lt;connection string name&gt;".</param>\n<param name='ResultType'>A value that defines structure of result: Records, Tuples, DataTable, or SqlDataReader.</param>\n<param name='SingleRow'>If set the query is expected to return a single row of the result set. See MSDN documentation for details on CommandBehavior.SingleRow.</param>\n<param name='ConfigFile'>The name of the configuration file that's used for connection strings at DESIGN-TIME. The default value is app.config or web.config.</param>\n<param name='AllParametersOptional'>If set all parameters become optional. NULL input values must be handled inside T-SQL.</param>\n<param name='ResolutionFolder'>A folder to be used to resolve relative file paths to *.sql script files at compile time. The default value is the folder that contains the project or script.</param>\n<param name='DataDirectory'>The name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.</param>"}
@rneatherway
Copy link
Contributor

Thanks for reporting. It seems the issue is due to the unescaped quotes " that have come from the doc comment for SqlCommandProvider. However, NewtonSoft should have quoted these, so I'm not quite sure why it is happening. I will investigate and post a fix next week.

@rneatherway
Copy link
Contributor

Something is going wrong with the unicode "smart quotes" in the docstring: https://github.com/fsprojects/FSharp.Data.SqlClient/blob/master/src/SqlClient/SqlCommandProvider.fs#L68

Are you running on Windows? This works fine on Linux, so perhaps the default encoding is at fault.

@rneatherway rneatherway added the bug label Sep 7, 2015
@bsermons
Copy link
Author

bsermons commented Sep 7, 2015

Yes this was on windows 8.1 machine I noticed it on. Is there something I can do to change the default encoding to see if that fixes it?

@rneatherway
Copy link
Contributor

There actually isn't a way without recompiling FsAutoComplete. If you could try setting the encoding to UTF8 that would be great. Just add System.Console.InputEncoding <- System.Text.Encoding.UTF8 at the beginning of the entry function in Program.fs, rebuild, and replace the copy that came with your fsharp-mode.

@bsermons
Copy link
Author

bsermons commented Sep 8, 2015

Setting the console InputEncoding to UTF8 didn't fix it but when I tried setting the OutputEncoding to UTF8, that seems to work.

@rneatherway
Copy link
Contributor

This should be fixed by #70, although emacs fsharp-mode will need to be updated to use the new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants