question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve Error Reporting: Make FS0039 easier to read at a glance.

See original GitHub issue

What

The following error message is super common and could be made less intimidating:

type Person = { Name : string }
let isaac = { Name = "Isaac" }
let fullName = isaac.Fooo + " Abraham" // The type 'Person' does not define the field, constructor or member 'Fooo'.

Why

The error message makes perfect sense, but for the beginner I feel it could be made more welcoming. In addition, the fact that it shows the type rather than the symbol name is a little confusing - especially if that type has been inferred.

How

I would prefer to see an error something like as follows:

  • isaac.Fooo does not exist (isaac is type Person).
  • Unknown member isaac.Fooo (isaac is type Person).

Notice that we use the same symbol name and path as the actual code sample, which hopefully draws people’s attention to the source of the issue. In the current error message, you have to read all the way to the end to see what the issue is.

I suppose we could keep the current “type-oriented” message but still improve it e.g.:

  • Fooo does not exist on the type Person.
  • Fooo does not exist on this symbol, which has type Person.

I’m not sure when else this error message is shown, so it’s possible I’ve missed some other obvious cases etc.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
ericsampsoncommented, Apr 19, 2022

Good point Isaac.

How about:

isaac.Fooo does not exist (isaac is of type Person, which does not define a field, constructor or member Fooo)

2reactions
isaacabrahamcommented, Apr 19, 2022

@edgarfgp we actually do that already, as long as the distance is not too far:

image

The key thing that Elm does here that F# doesn’t is that the error message refers to the symbol (issac) where in F# it simply mentions the type (Person).

Read more comments on GitHub >

github_iconTop Results From Across the Web

FS0039: The namespace is not defined
I've reproduced what you're seeing. The problem appears to be caused by a design-time error in the FSharp.Data type provider.
Read more >
new Bolero, FSharp.CosmosDb and C# 11 Preview
Reading through F# Weekly with StachuDotNet - Twitch · Absolute Beginner's guide To F# ... Improve Error Reporting: Make FS0039 easier to read...
Read more >
frustrated by F#, can I get this to work? (install a package ...
C:\Users\User\Desktop\testf#\myprogram.fsx(3,6): error FS0039: The namespace or module 'FSharpx' is not defined.
Read more >
Troubleshooting F# | F# for fun and profit
I will first present some general advice on troubleshooting and some of the most common errors that beginners make. After that, I will...
Read more >
A Peek into F# 4.1 - .NET Blog
This is an ongoing process, and we'll continue to see improvements to error messages even past F# 4.1. If you notice an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found