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

Github job fails with Fable for OSX runners #4014

Closed
halcwb opened this issue Jan 17, 2025 · 16 comments
Closed

Github job fails with Fable for OSX runners #4014

halcwb opened this issue Jan 17, 2025 · 16 comments

Comments

@halcwb
Copy link

halcwb commented Jan 17, 2025

Build fails using the new Fable compiler but only when running as a github job, with the following stack trace:

client: Unhandled exception. System.Text.Json.JsonReaderException: 'W' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
client: at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) client: at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) client: at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) client: at System.Text.Json.Utf8JsonReader.ReadSingleSegment() client: at System.Text.Json.Utf8JsonReader.Read() client: at System.Text.Json.JsonDocument.Parse(ReadOnlySpan1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
client: at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) client: at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory1 json, JsonDocumentOptions options)
client: at Fable.Compiler.MSBuildCrackerResolverModule.mkOptionsFromDesignTimeBuildAux@80-1.Invoke(String targetFrameworkJson) in /workspaces/Fable/src/Fable.Compiler/MSBuildCrackerResolver.fs:line 82
client: at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation1 ctxt, b result1, FSharpFunc2 userCode) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 528
client: at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112 client: --- End of stack trace from previous location --- client: at Microsoft.FSharp.Control.AsyncResult1.Commit() in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 454
client: at Microsoft.FSharp.Control.AsyncPrimitives.RunImmediate[a](CancellationToken cancellationToken, FSharpAsync1 computation) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1163 client: at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync1 computation, FSharpOption1 timeout) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1169 client: at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync1 computation, FSharpOption1 timeout, FSharpOption1 cancellationToken) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1519
client: at Fable.Compiler.ProjectCracker.crackMainProject(ProjectCrackerResolver resolver, CrackerOptions opts) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 546
client: at Fable.Compiler.ProjectCracker.getCrackedProjectsFromMainFsproj(ProjectCrackerResolver resolver, CrackerOptions opts) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 582
client: at Fable.Compiler.ProjectCracker.getCrackedProjects(ProjectCrackerResolver resolver, CrackerOptions opts) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 602
client: at Fable.Compiler.ProjectCracker.retry@612(ProjectCrackerResolver resolver, CrackerOptions opts, DateTime retryUntil, Unit unitVar0) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 614
client: at Fable.Compiler.ProjectCracker.retryGetCrackedProjects(ProjectCrackerResolver resolver, CrackerOptions opts) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 624
client: at Fable.Compiler.ProjectCracker.getFullProjectOpts(ProjectCrackerResolver resolver, CrackerOptions opts) in /workspaces/Fable/src/Fable.Compiler/ProjectCracker.fs:line 921
client: at Fable.Compiler.Util.Performance.measure[a](FSharpFunc2 f) in /workspaces/Fable/src/Fable.Compiler/Util.fs:line 835 client: at Fable.Cli.Main.ProjectCracked.Init(CliArgs cliArgs, Boolean useMSBuildForCracking, FSharpOption1 evaluateOnly) in /workspaces/Fable/src/Fable.Cli/Main.fs:line 373
client: at Fable.Cli.Main.compilationCycle@1001.Invoke(Unit unitVar) in /workspaces/Fable/src/Fable.Cli/Main.fs:line 1011
client: at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation1 ctxt, TResult result1, FSharpFunc2 part2) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 510
client: at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 112 client: --- End of stack trace from previous location --- client: at Microsoft.FSharp.Control.AsyncResult1.Commit() in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 454
client: at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync1 computation, FSharpOption1 timeout) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1143
client: at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync1 computation, FSharpOption1 timeout) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1170
client: at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync1 computation, FSharpOption1 timeout, FSharpOption1 cancellationToken) in /home/dev/Projects/fsharp/src/FSharp.Core/async.fs:line 1519 client: at [email protected](Unit _arg5) in /workspaces/Fable/src/Fable.Cli/Entry.fs:line 394 client: at [email protected](Tuple2 _arg2) in /workspaces/Fable/src/Fable.Cli/Entry.fs:line 541
client: at Fable.Cli.Entry.main(String[] argv) in /workspaces/Fable/src/Fable.Cli/Entry.fs:line 533

See: https://github.com/halcwb/PICEDashboard/actions/runs/12815301082.

But the job on Ubuntu passses! Also on my local macbook pro I have no problem?

.NET SDK:
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.3068a692
MSBuild version: 17.12.12+1cce77968

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.6
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/9.0.101/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.0
Architecture: arm64
Commit: 9d5a6a9aa4

.NET SDKs installed:
6.0.415 [/usr/local/share/dotnet/sdk]
7.0.402 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
9.0.100 [/usr/local/share/dotnet/sdk]
9.0.101 [/usr/local/share/dotnet/sdk]

@MangelMaxime
Copy link
Member

I am also able to compile it on my Mac locally, not sure what is wrong on Github CI.

Does previous version of Fable works?

I also noted in the CI log that it says it installed version 9.0.102 of .NET but then it mention 9.0.101, can you please try to force the a specific version of .NET instead of 9.0.x ?

Image

@MangelMaxime
Copy link
Member

Problems don't seems related to your project and seems to happens with previous version of Fable too.

I have a similar error on this repo https://github.com/thoth-org/Thoth.Json/actions/runs/12873451418/job/35891008876 where I am using Fable 4.24.0.

Seems like there is something wrong in Mac OS CI on Github...

@MangelMaxime MangelMaxime changed the title Github job fails with fable 5.0.0-alpha.5 Github job fails with Fable Jan 20, 2025
@MangelMaxime MangelMaxime changed the title Github job fails with Fable Github job fails with Fable for OSX runners Jan 20, 2025
@MangelMaxime
Copy link
Member

I reported an issue on Github Images repo as I don't know how to debug this problem.

actions/runner-images#11434

On my repo previous CI run worked fine and now the same version of Fable and .NET fails with the same error as yours.

@MangelMaxime
Copy link
Member

@halcwb According to the Github teams using macos-14 instead of macos-latest fix the issue at least it did it for Thoth.Json reproduction repository.

I am trying to check if they can continue to investigate or why macos-latest fails because I fear that this is a workaround and the issue could appear again.

@halcwb
Copy link
Author

halcwb commented Jan 21, 2025

@MangelMaxime 👍
Didn't have much time to look into this any further. Though wat could be of help is using https://github.com/nektos/act. Act allows you to run the github jobs on your local machine, just as a github job without actually touching the remote repository.

@nojaf
Copy link
Member

nojaf commented Jan 22, 2025

Tremendous shot in the dark but maybe you ran into a problem with project cracking in

$"/restore /t:%s{targets} %s{properties} --getItem:FscCommandLineArgs --getItem:ProjectReference --getProperty:OutputType -warnAsMessage:NU1608"

I recently added nojaf/vite-plugin-fable@8d9a6ee to avoid the NU1605 warning.

It looks like the JSON parsing of the msbuild output doesn't work because of a warning.

'W' is an invalid start of a value.

Makes me suspect the output there was something like:

Warning blah
{ ...json }

Could you try with the build analyzer project cracking?

@MangelMaxime
Copy link
Member

It looks like the JSON parsing of the msbuild output doesn't work because of a warning.

'W' is an invalid start of a value.

Makes me suspect the output there was something like:

Warning blah
{ ...json }

This could definitely makes sense indeed, but I wonder why we don't see it when running on others CI or my machine locally.

If this is the case, I think adding a try ... catch and logging the string we get from MSBuild could be a good idea to make identifying similar issues easier in the future.

Could you try with the build analyzer project cracking?

You mean the legacy resolver tool ? Will do.

@MangelMaxime
Copy link
Member

Could you try with the build analyzer project cracking?

You mean the legacy resolver tool ? Will do.

CI is green for me when using BuildAlyzer for cracking the project

@MangelMaxime
Copy link
Member

After looking at the log from Thoth.Json CI again, I found out that the JSON that we fail to parse comes from (line 82):

let! targetFrameworkJson =
dotnet_msbuild
fsproj.FullName
$"%s{configurationProperty} --getProperty:TargetFrameworks --getProperty:TargetFramework"
let targetFramework =
let properties =
JsonDocument.Parse targetFrameworkJson
|> fun json -> json.RootElement.GetProperty "Properties"

I tried to reproduce the issue by making Thoth.Json CI run dotnet msbuild "tests/Thoth.Json.Tests.JavaScript" /p:Configuration=Release --getProperty:TargetFrameworks --getProperty:TargetFramework to see the result of MSBuild but up to now I was not successful to finding a JSON starting with W.

I will give it some more try, and if I am stuck I think I will release a version of Fable with try ... with around the JSON parser to see what is actually happening.

@MangelMaxime
Copy link
Member

@MangelMaxime 👍
Didn't have much time to look into this any further. Though wat could be of help is using nektos/act. Act allows you to run the github jobs on your local machine, just as a github job without actually touching the remote repository.

They don't seems to use the exact same images as Github CI, which prevent us from reproducing the issue unfortunately.

@nojaf
Copy link
Member

nojaf commented Jan 23, 2025

Yeah, I think it is a very specific version of the dotnet SDK which gives slightly different nuget restore behavior. In my case F# Core was degraded during restore and that prompt a warning.

@MangelMaxime
Copy link
Member

Ok so it seems like the problem is not coming from a MSBuild warning but because of dotnet Welcome message...

2025-01-23T08:52:42.7757190Z JSON:
2025-01-23T08:52:42.7758580Z Welcome to .NET 9.0!
2025-01-23T08:52:42.7759300Z ---------------------
2025-01-23T08:52:42.7760090Z SDK Version: 9.0.102
2025-01-23T08:52:42.7760530Z 
2025-01-23T08:52:42.7760860Z Telemetry
2025-01-23T08:52:42.7761550Z ---------
2025-01-23T08:52:42.7765400Z The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
2025-01-23T08:52:42.7771790Z 
2025-01-23T08:52:42.7772450Z Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
2025-01-23T08:52:42.7772910Z 
2025-01-23T08:52:42.7772990Z ----------------
2025-01-23T08:52:42.7773660Z Installed an ASP.NET Core HTTPS development certificate.
2025-01-23T08:52:42.7774260Z To trust the certificate, run 'dotnet dev-certs https --trust'
2025-01-23T08:52:42.7775040Z Learn about HTTPS: https://aka.ms/dotnet-https
2025-01-23T08:52:42.7775240Z 
2025-01-23T08:52:42.7775430Z ----------------
2025-01-23T08:52:42.7775890Z Write your first app: https://aka.ms/dotnet-hello-world
2025-01-23T08:52:42.7777920Z Find out what's new: https://aka.ms/dotnet-whats-new
2025-01-23T08:52:42.7778630Z Explore documentation: https://aka.ms/dotnet-docs
2025-01-23T08:52:42.7779360Z Report issues and find source on GitHub: https://github.com/dotnet/core
2025-01-23T08:52:42.7780130Z Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
2025-01-23T08:52:42.7780890Z --------------------------------------------------------------------------------------
2025-01-23T08:52:42.7782380Z {
2025-01-23T08:52:42.7782670Z   "Properties": {
2025-01-23T08:52:42.7782910Z     "TargetFrameworks": "",
2025-01-23T08:52:42.7783410Z     "TargetFramework": "netstandard2.0"
2025-01-23T08:52:42.7783690Z   }
2025-01-23T08:52:42.7783900Z }
2025-01-23T08:52:42.7784090Z 
2025-01-23T08:52:42.7784210Z Exception:
2025-01-23T08:52:42.7785340Z System.Text.Json.JsonReaderException: 'W' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

Looking further it appears that we get dotnet welcome message twice in the CI:

  1. When running dotnet tool restore which start the build system in my repo

    Welcome to .NET 8.0!
    ---------------------
    SDK Version: 8.0.405
    
    Telemetry
    ---------
    The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
    
    [...]
    --------------------------------------------------------------------------------------
    Tool 'fable' (version '4.24.0') was restored. Available commands: fable
    Tool 'fantomas' (version '6.3.[16](https://github.com/thoth-org/Thoth.Json/actions/runs/12916208270/job/36019860223#step:8:17)') was restored. Available commands: fantomas
    Tool 'husky' (version '0.6.3') was restored. Available commands: husky
    Tool 'easybuild.commitlinter' (version '1.0.1') was restored. Available commands: commit-linter
    Tool 'easybuild.changeloggen' (version '4.0.0') was restored. Available commands: changelog-gen
    
  2. When running dotnet msbuild from inside Fable

    Parsing Thoth.Json.Tests.JavaScript.fsproj...
    Unhandled exception. System.Exception: Failed to parse MSBuild output
    JSON:
    Welcome to .NET 9.0!
    ---------------------
    SDK Version: 9.0.102
    
    [...]
    --------------------------------------------------------------------------------------
    {
      "Properties": {
        "TargetFrameworks": "",
        "TargetFramework": "netstandard2.0"
      }
    }
    
    Exception:
    System.Text.Json.JsonReaderException: 'W' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
    

I believe this is because dotnet restore is running from the local repository Folder which has a global.json file forcing .NET 8 usage.

However, dotnet msbuild is run from fable assembly location so outside of the repository folder.

https://github.com/fable-compiler/Fable/blob/main/src/Fable.Compiler/MSBuildCrackerResolver.fs#L31-L36

The reason why didn't have this issue in the past is probably because people using --test:msbuildcracker had their project updated to .NET 8 and .NET 8 was the latest version so also used when called outside of the repository directory.

From here it shows potential trouble I believe:

  1. If the user don't have .NET 8+ installed the can't use fable 5 but I also think it will probably not be possible to install it at all in this case because Fable is net8.0 tool
  2. If 1 is not an issue, we probably just need to find a way to disable .NET welcome message. Perhaps there is a env variable for that or we could run dotnet --version at the start of the cracker process to force the welcome message in a situation which is harmless to us.

@MangelMaxime
Copy link
Member

It seems like there is DOTNET_NOLOGO

Specifies whether .NET welcome and telemetry messages are displayed on the first run. Set to true to mute these messages (values true, 1, or yes accepted) or set to false to allow them (values false, 0, or no accepted). If not set, the default is false and the messages will be displayed on the first run. This flag does not affect telemetry (see DOTNET_CLI_TELEMETRY_OPTOUT for opting out of sending telemetry).

I am giving it a try in Thoth.Json CI to see if this solves the issue.

@nojaf
Copy link
Member

nojaf commented Jan 23, 2025

However, dotnet msbuild is run from fable assembly location so outside of the repository folder.

It is running from the user folder:

psi.WorkingDirectory <- Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

If the user don't have .NET 8+ installed the can't use fable 5 but I also think it will probably not be possible to install it at all in this case because Fable is net8.0 tool

It won't be possible for to install. net6.0 and net7.0 are no longer supported, so I don't think a free open source project should bother really.

@MangelMaxime
Copy link
Member

However, dotnet msbuild is run from fable assembly location so outside of the repository folder.

It is running from the user folder:

Fable/src/Fable.Compiler/MSBuildCrackerResolver.fs

Line 36 in d4541ba

psi.WorkingDirectory <- Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

You are right, I was focused on:

let pwd = Assembly.GetEntryAssembly().Location |> Path.GetDirectoryName

Which don't seems to be used outside of logging, I will update pwd to use the same value where we actually start the process.

@MangelMaxime
Copy link
Member

MangelMaxime commented Jan 23, 2025

Fable 5.0.0-alpha.7 should fix this issue.

Github CI is working for me with this version for Thoth.Json.

Thanks all for the help, feel free to re-open the issue if needed.

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

No branches or pull requests

3 participants