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

[dd-dotnet] Catch error when failing to read env vars on IIS #6430

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#pragma warning disable SA1108 // BlockStatementsMustNotContainEmbeddedComments
Copy link
Member

Choose a reason for hiding this comment

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

I "love" that you disabled this instead of just moving the comment inside the catch 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My comment is at the right place and I'm willing to die on that hill


using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Datadog.Trace.Tools.dd_dotnet.Checks.Windows.IIS
{
Expand Down Expand Up @@ -55,14 +58,21 @@ public IReadOnlyDictionary<string, string> GetEnvironmentVariables()
{
var result = new Dictionary<string, string>();

using var environmentVariables = _applicationPool.GetElementByName("environmentVariables");
using var collection = environmentVariables.Collection();
var count = collection.Count();
try
{
using var environmentVariables = _applicationPool.GetElementByName("environmentVariables");
using var collection = environmentVariables.Collection();
var count = collection.Count();

for (int i = 0; i < count; i++)
for (int i = 0; i < count; i++)
{
using var item = collection.GetItem(i);
result.Add(item.GetStringProperty("name"), item.GetStringProperty("value"));
}
}
catch (Win32Exception ex) when ((uint)ex.NativeErrorCode == 0x80070585) // Invalid index
{
using var item = collection.GetItem(i);
result.Add(item.GetStringProperty("name"), item.GetStringProperty("value"));
Utils.WriteWarning("Could not read IIS environment variables. This is expected if using a version of IIS prior to 10.");
}

return result;
Expand Down
Loading