ForNeVeR / ForNeVeR/Todosaurus

CLI stops with NullReferenceException if CI is set and GITHUB_WORKSPACE is not set

Open Beginner friendly
#327 0 comments 0 reactions 0 assignees View on GitHub
bug good first issue help wanted
Dominant language
Kotlin
Stars
22
Forks
5
Avg merge
2d 20h
Merged PRs (30d)
8

Description

## Problem

The CLI tool stops with a `NullReferenceException` if the `CI` environment variable has a value and the `GITHUB_WORKSPACE` environment variable has no value.

`Env.IsCi()` gives `true` for each value of `CI` that is not `0` and not `false`. Then `Logger.Warning` calls `FormatCiMessage`, and this function reads `Env.CiWorkspace`. `CiWorkspace` applies `nonNull` to `GITHUB_WORKSPACE`. Only GitHub Actions sets `GITHUB_WORKSPACE`. Other continuous integration systems set `CI` to `true`, but they do not set `GITHUB_WORKSPACE`. Examples of these systems are GitLab CI, TeamCity and Azure Pipelines.

The error occurs at the first warning message. The tool stops exactly when it finds an unresolved TODO item. If the repository has no unresolved TODO item, the tool does not show the defect.

## How to repeat the problem

1. Get a repository that has one unresolved TODO item.
2. Set the `CI` environment variable to `1`.
3. Make sure the `GITHUB_WORKSPACE` environment variable has no value.
4. Run `todosaurus`.

Version of the tool: `1.12.0+421125370c1170caba9522faad5bb5930d4c109a`.

## Actual result

The tool stops. It shows no warning and no report.

```
Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Todosaurus.Cli.Env.CiWorkspace@20.Invoke(Unit unitVar) in /_//cli/Cli/Env.fs:line 20
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Todosaurus.Cli.Logger.FormatCiMessage(String title, String message, SourceInfo sourceInfo) in /_//cli/Cli/Logger.fs:line 29
at Todosaurus.Cli.Logger.Warning(LoggerContext ctx, String title, String message, SourceInfo sourceInfo) in /_//cli/Cli/Logger.fs:line 56
at Todosaurus.Cli.ScanCommand.Scan@126.MoveNext() in /_//cli/Cli/ScanCommand.fs:line 142
at Todosaurus.Cli.ScanCommand.RunScan@207.MoveNext() in /_//cli/Cli/ScanCommand.fs:line 215
at System.CommandLine.Command.<>c__DisplayClass34_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
```

## Necessary result

The tool shows one warning for each unresolved TODO item. Then the tool gives the usual exit code.

## Why this task is necessary

Continuous integration is the primary use of this tool. In each system that is not GitHub Actions, the tool gives no report. The user gets an error message about a defect in the tool in place of a list of the unresolved TODO items. The user can also get this error on a local machine, because some tools set the `CI` variable.

## Temporary solution for the user

Remove the `CI` environment variable before you run the tool.

## Possible correction

Give a default value to `CiWorkspace`: use the working directory if `GITHUB_WORKSPACE` has no value. As an alternative, give the value `true` from `IsCi()` for the GitHub message format only if `GITHUB_ACTIONS` or `GITHUB_WORKSPACE` also has a value.

## Code

- https://github.com/ForNeVeR/Todosaurus/blob/421125370c1170caba9522faad5bb5930d4c109a/cli/Cli/Env.fs#L20
- https://github.com/ForNeVeR/Todosaurus/blob/421125370c1170caba9522faad5bb5930d4c109a/cli/Cli/Logger.fs#L29

Contributor guide

Open the contributing guide

Research direction

Start with cli/Cli/Env.fs at CiWorkspace and cli/Cli/Logger.fs at FormatCiMessage, then reproduce with CI=1 and no GITHUB_WORKSPACE in a repository containing an unresolved TODO. Check the existing warning path and its related environment handling. Done means each unresolved TODO produces its warning and the usual exit code without a NullReferenceException.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.