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

Add Roslyn Analyser to detect common problems #45

Open
adam-resdiary opened this issue Oct 7, 2020 · 0 comments
Open

Add Roslyn Analyser to detect common problems #45

adam-resdiary opened this issue Oct 7, 2020 · 0 comments
Labels
type/epic Used to describe a larger chunk of work that will need to be broken down into further tasks

Comments

@adam-resdiary
Copy link
Collaborator

adam-resdiary commented Oct 7, 2020

We can potentially create Roslyn Analysers to detect common issues when people are using the runtime library or generated code. Examples of problems we can detect are:

  • Returning null from a service method.
  • Throwing an exception that isn't part of the service method definition.

To illustrate this, let's take the example of returning null from a service method. Thrift doesn't support null return results from service methods, and has no way to serialise that. So if someone writes the following code:

public async Task<User> GetUser(int userId)
{
    var user = this.userRepository.GetById(userId);

    if (user != null)
    {
        return this.mapper.Map<User>(user);
    }

    return null;
           ^^^^
}

We can report an error when returning null since we know that it isn't a valid return result.

An example of a project that provides analysers like this is xUnit. It can detect problems like Theories not having the correct parameters passed to them at compile time, something that would typically cause a runtime error.

@adam-resdiary adam-resdiary added the type/epic Used to describe a larger chunk of work that will need to be broken down into further tasks label Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/epic Used to describe a larger chunk of work that will need to be broken down into further tasks
Projects
None yet
Development

No branches or pull requests

1 participant