Skip to content

Commit 31ad867

Browse files
authored
fix: Catching UnauthorizedAccessException trying to write files to a … (#179)
* fix: Catching UnauthorizedAccessException trying to write files to a path without permissions * fix: ErrorHandler * chore: Upgrade .NET and nuget-packages * chore: Disable build for CodeQL * ci: Trying to get CodeQL to work as it should for build-mode none.
1 parent 40f2687 commit 31ad867

File tree

12 files changed

+54
-49
lines changed

12 files changed

+54
-49
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,24 @@ jobs:
1717
name: Analyze
1818
runs-on: windows-latest
1919

20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
# Override automatic language detection by changing the below list
24-
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
25-
language: ['csharp']
26-
# Learn more...
27-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
28-
2920
steps:
3021
- name: Checkout repository
31-
uses: actions/checkout@v3
32-
22+
uses: actions/checkout@v4
23+
3324
- name: Setup .NET
3425
uses: actions/setup-dotnet@v3
3526
with:
36-
dotnet-version: '8.0'
27+
dotnet-version: '9.0'
3728

3829
# Initializes the CodeQL tools for scanning.
3930
- name: Initialize CodeQL
40-
uses: github/codeql-action/init@v2
31+
uses: github/codeql-action/init@v3
4132
with:
42-
languages: ${{ matrix.language }}
43-
# If you wish to specify custom queries, you can do so here or in a config file.
44-
# By default, queries listed here will override any specified in a config file.
45-
# Prefix the list here with "+" to use these queries and those in the config file.
46-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
33+
languages: csharp
34+
build-mode: none
4735

48-
- name: Build L10n
49-
run: |
50-
dotnet restore
51-
dotnet build
36+
- name: Autobuild
37+
uses: github/codeql-action/autobuild@v3
5238

5339
- name: Perform CodeQL Analysis
54-
uses: github/codeql-action/analyze@v2
40+
uses: github/codeql-action/analyze@v3

MN.L10n.Analyzer/MN.L10n.Analyzer.Test/MN.L10n.Analyzer.Test.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="FakeItEasy" Version="8.1.0" />
10-
<PackageReference Include="coverlet.collector" Version="6.0.0">
9+
<PackageReference Include="FakeItEasy" Version="8.3.0" />
10+
<PackageReference Include="coverlet.collector" Version="6.0.4">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
16-
<PackageReference Include="xunit" Version="2.6.5" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
14+
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.13.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
16+
<PackageReference Include="xunit" Version="2.9.3" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>

MN.L10n.Analyzer/MN.L10n.Analyzer/MN.L10n.Analyzer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</PropertyGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
33+
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.13.0" />
3434
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
3535
</ItemGroup>
3636

MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ApplicationIcon />
66
<OutputType>Exe</OutputType>
77
<StartupObject>MN.L10n.BuildTasks.Program</StartupObject>

MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
66
<RepositoryUrl>https://github.com/MultinetInteractive/MN.L10n</RepositoryUrl>
77
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
@@ -11,9 +11,9 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
15-
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
16-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
15+
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.3.0" />
16+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.3" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

MN.L10n.JavascriptTranslationMiddleware/MN.L10n.JavascriptTranslationMiddleware.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
55
<Nullable>Enable</Nullable>
66
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
77
<PackageVersion>3.0.0</PackageVersion>

MN.L10n.TestWebApp/MN.L10n.TestWebApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<RootNamespace>TheTest</RootNamespace>
55
<Authors>lice, chbe</Authors>
66
<RepositoryUrl>https://github.com/MultinetInteractive/MN.L10n</RepositoryUrl>

MN.L10n.Tests/MN.L10n.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="FakeItEasy" Version="8.1.0" />
10-
<PackageReference Include="coverlet.collector" Version="6.0.0">
9+
<PackageReference Include="FakeItEasy" Version="8.3.0" />
10+
<PackageReference Include="coverlet.collector" Version="6.0.4">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15-
<PackageReference Include="xunit" Version="2.6.5" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15+
<PackageReference Include="xunit" Version="2.9.3" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>

MN.L10n.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1010
.editorconfig = .editorconfig
1111
.gitattributes = .gitattributes
1212
.gitignore = .gitignore
13+
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
1314
CONTRIBUTING.md = CONTRIBUTING.md
15+
.github\workflows\javascripts-tests.yml = .github\workflows\javascripts-tests.yml
1416
LICENSE.txt = LICENSE.txt
1517
README.md = README.md
1618
TROUBLESHOOTING.md = TROUBLESHOOTING.md

MN.L10n/FileProviders/FileDataProvider.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public class FileDataProvider : IL10nDataProvider
2323
private string LanguagesFile { get; set; }
2424
private string LanguageFile { get; set; }
2525
public bool SaveChangesToDisk { get; set; } = true;
26-
26+
27+
public Action<string, string, Exception>? OnWriteError { get; set; }
28+
2729
public FileDataProvider(string path, string l10nFileName = "phrases.json", string l10nPhraseFileNameFormat = "language-{0}.json", string l10nLanguagesFileName = "languages.json")
2830
{
2931
FilePath = path;
@@ -157,7 +159,7 @@ public async Task<bool> LoadTranslationFromSources(L10n l10n, bool removeAllPhra
157159
sources.Reverse();
158160

159161
// If we have sources, and the removeAllPhrases is true, remove all current phrases, to get rid of old ones as well
160-
if(sources.Count > 0 && removeAllPhrases)
162+
if (sources.Count > 0 && removeAllPhrases)
161163
{
162164
l10nLang.Phrases.Clear();
163165
}
@@ -237,7 +239,22 @@ private void WriteToDiskIfAllowed(string pathAndFilename, string contents)
237239
{
238240
if (SaveChangesToDisk)
239241
{
240-
File.WriteAllText(pathAndFilename, contents);
242+
try
243+
{
244+
File.WriteAllText(pathAndFilename, contents);
245+
}
246+
catch (UnauthorizedAccessException uae)
247+
{
248+
Console.WriteLine("error l10n: Unauthorized Access Exception");
249+
Console.WriteLine($"error l10n: Got an error trying to save the file {pathAndFilename}");
250+
Console.WriteLine(uae.ToString());
251+
252+
OnWriteError?.Invoke(pathAndFilename, contents, uae);
253+
}
254+
catch (Exception ex)
255+
{
256+
OnWriteError?.Invoke(pathAndFilename, contents, ex);
257+
}
241258
}
242259
}
243260
}

0 commit comments

Comments
 (0)