Skip to content

Enable WarningsAsErrors (except in Debug mode) - #273

Open
knocte wants to merge 5 commits into
fsprojects:masterfrom
knocte:wip/updateDepsToFixSecurityIssuesReportedAsWarnings
Open

knocte wants to merge 5 commits into
fsprojects:masterfrom
knocte:wip/updateDepsToFixSecurityIssuesReportedAsWarnings

Conversation

@knocte

@knocte knocte commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

It should be useful* to catch warnings early at CI time, while leaving them live in Debug mode (in case some developer is debugging something locally, we don't want warnings to get in the way in that case).

* Especially because the build is right now (before this PR is/was merged) reporting security vulnerabilities in some nuget dependencies (see each commit msg independently for more details).

It should be useful to catch warnings early at CI time, while
leaving them live in Debug mode (in case some developer is
debugging something locally, we don't want warnings to get in
the way in that case).
Updated the dependencies to resolve the security vulnerabilities:

 1. In paket.dependencies under group Build:
     - Pinned Microsoft.NET.StringTools ~> 17.11.48 to align with the existing
       Microsoft.Build 17.11.48 packages and avoid pulling in newer versions
       targeting .NET 11+.
     - Added version constraints to resolve the security advisories:
         - NuGet.Packaging >= 7.0.3 (fixes GHSA-g4vj-cjjj-v7hg)
         - NuGet.Protocol >= 7.0.3 (fixes GHSA-g4vj-cjjj-v7hg)
         - System.Security.Cryptography.Pkcs >= 10.0.14 (fixes GHSA-2fmv-rv2c-59x7
           and GHSA-846f-f764-76mx)

 2. Updated paket.lock with the resolved patched package versions.

The (warnings as) errors were:
```
Run dotnet run --project build/build.fsproj
/home/runner/work/FSharpx.Collections/FSharpx.Collections/build/build.fsproj : error NU1901: Warning As Error: Package 'NuGet.Packaging' 7.0.1 has a known low severity vulnerability, GHSA-g4vj-cjjj-v7hg
/home/runner/work/FSharpx.Collections/FSharpx.Collections/build/build.fsproj : error NU1901: Warning As Error: Package 'NuGet.Protocol' 7.0.1 has a known low severity vulnerability, GHSA-g4vj-cjjj-v7hg
/home/runner/work/FSharpx.Collections/FSharpx.Collections/build/build.fsproj : error NU1902: Warning As Error: Package 'System.Security.Cryptography.Pkcs' 10.0.1 has a known moderate severity vulnerability, GHSA-2fmv-rv2c-59x7
/home/runner/work/FSharpx.Collections/FSharpx.Collections/build/build.fsproj : error NU1903: Warning As Error: Package 'System.Security.Cryptography.Pkcs' 10.0.1 has a known high severity vulnerability, GHSA-846f-f764-76mx

The build failed. Fix the build errors and run again.
Error: Process completed with exit code 1.
```
Example of one occurrence:
```
src/FSharpx.Collections/LazyList.fs(169,22): warning FS3218: The argument
names in the signature 'source' and implementation 's1' do not match.
The argument name from the signature file will be used. This may cause
problems when debugging or profiling.
```
After we enabled TreatWarningsAsErrors in Directory.Build.props
then we were getting this warning in the Fable tests:

```
Error: tests/fable/FSharpx.Collections.Tests/LazyList.test.fs(35,55): error FS0040: This
and other recursive references to the object(s) being defined will be checked for
initialization-soundness at runtime through the use of a delayed reference. This is
because you are defining one or more recursive objects, rather than recursive functions.
This warning may be suppressed by using '#nowarn "40"' or '--nowarn:40'.
[/home/runner/work/FSharpx.Collections/FSharpx.Collections/tests/fable/FSharpx.Collections.Tests/FSharpx.Collections.Tests.fsproj]
    0 Warning(s)
    1 Error(s)
```

Not sure how to fix it, but honestly maybe it's not worth it,
since these are just tests, so let's override WarningsAsErrors
here to keep it disabled as it was before.
By updating this then we already fix security vulnerabilities
from dependencies without the need to pin.
@knocte
knocte force-pushed the wip/updateDepsToFixSecurityIssuesReportedAsWarnings branch from db517f0 to cb3416b Compare November 10, 2026 08:15
@gdziadkiewicz

Copy link
Copy Markdown
Collaborator

Great idea! Reviewing

Comment thread paket.lock
FSharp.Core (>= 4.3.4) - restriction: || (== net8.0) (&& (== netstandard2.0) (>= net461)) (&& (== netstandard2.0) (>= netcoreapp2.0))
System.Collections.Immutable (>= 1.4) - restriction: || (== net8.0) (&& (== netstandard2.0) (>= net461)) (&& (== netstandard2.0) (>= netcoreapp2.0))

GROUP Build

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I see that we are not changing the deps of the library itself, only stuff used in the build pipeline.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The warnings-as-errors policy unintentionally applies to default Debug builds, risking CI and local build failures, while failing to cover either shipped library.

2 open issues
What changed in this PR

Introduces a warnings-as-errors policy intended to catch issues in CI while preserving non-failing warnings in Debug builds.

Changes:

  • Adds conditional warning enforcement, with an explicit Fable test-project exemption.
  • Aligns LazyList implementation parameter names and related exception text with existing signatures.
  • Updates NuGet tooling and cryptography dependencies in the build-tooling dependency group.
File Description
tests/​fable/​FSharpx.Collections.Tests/​FSharpx.Collections.Tests.fsproj Exempts Fable tests from warnings-as-errors.
src/​FSharpx.Collections/​LazyList.fs Aligns parameter names with signatures to resolve warnings.
paket.lock Updates build-tooling dependencies to address reported vulnerabilities.
Directory.Build.props Adds the conditional warnings-as-errors policy.

Review effort: Balanced

Comment thread Directory.Build.props
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Condition=" '$(Configuration)' != 'Debug' ">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, Copilot?

I will test it locally and comment here on results:

  1. VS build in debug and release
  2. cli dotnet build with specified configuration and without both debug and release
  3. Fake builds

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: when Configuration is omitted, the condition runs before the SDK sets its Debug default. The final properties are Configuration=Debug and TreatWarningsAsErrors=true; explicitly passing Debug gives false.

The suggestion fixes that, let's commit it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdziadkiewicz Wouldn't committing this change mean that the final binaries submitted to nuget have Configuration=Debug instead of Configuration=Release?

@gdziadkiewicz gdziadkiewicz Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the suggested default would apply only when Configuration is not supplied.

The FAKE script defaults the build configuration to Release, allows it to be overridden by the configuration environment variable, and passes the resulting value explicitly to the solution build. The NuGet targets then use Paket to pack.

The unqualified dotnet run --project build/build.fsproj builds the FAKE driver in Debug by default. That is separate from the Release configuration the driver passes to the solution build. Same for dotnet build calls for single projects.

Comment thread Directory.Build.props
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Condition=" '$(Configuration)' != 'Debug' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check if this is true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also turned out to be true, let's import the policy from src/Directory.Build.props with

<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.props" />

@gdziadkiewicz gdziadkiewicz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in comments

@knocte

knocte commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

This also turned out to be true

If that were the case, why did CI fail at the first commit cb3416b?

@gdziadkiewicz

Copy link
Copy Markdown
Collaborator

This also turned out to be true

If that were the case, why did CI fail at the first commit cb3416b?

The CI failure was in build/build.fsproj, which picks up the root Directory.Build.props. Its NuGet vulnerability warnings were treated as errors. The library projects find src/Directory.Build.props first, so they don’t pick up the root policy. They are the problem.

I made a demonstration branch based on this PR. It reintroduces one LazyList parameter-name mismatch. Please see here that the parameter mismatch is a warning, not error despite release config being used https://github.com/fsprojects/FSharpx.Collections/actions/runs/43323472080/job/131549882908
image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants