Skip to content

Fix handling of empty 'urlsToWatch' in plugins #533

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

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

SilentSobs
Copy link
Contributor

@SilentSobs SilentSobs commented Jan 29, 2024

Issue #527

This commit resolves an issue where plugins defining an empty array for 'urlsToWatch' would result in the plugin being disabled. The code has been modified to check for both null and empty arrays, and in both cases, it now defaults to using the global list of URLs. This ensures that plugins remain active even when no specific URLs are provided.

  • Modified the code to handle empty 'urlsToWatch' arrays.
  • Added a check for both null and empty arrays.
  • Plugins now default to using the global list of URLs when 'urlsToWatch' is empty.

Let's confirm this:

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.15.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "plugins\\dev-proxy-plugins.dll"
    },
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "plugins\\dev-proxy-plugins.dll",
      "configSection": "genericRandomErrorPlugin",
      "urlsToWatch": []  // Empty array indicates that it now defaults to using the global list of URLs
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "genericRandomErrorPlugin": {
    "errorsFile": "devproxy-errors.json"
  },
  "rate": 50,
  "labelMode": "text",
  "logLevel": "info",
  "newVersionNotification": "stable"
}

As you can see, I have added a comment to the urlsToWatch array in the GenericRandomErrorPlugin block to explicitly state that the empty array indicates that it now defaults to using the global list of URLs. This helps in providing a clear and concise explanation of the purpose of the empty array.

Now let's test

image

Now let's change it

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.15.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "plugins\\dev-proxy-plugins.dll",
      "urlsToWatch": []  // Empty array indicates that it now defaults to using the global list of URLs
    },
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "plugins\\dev-proxy-plugins.dll",
      "configSection": "genericRandomErrorPlugin",
   
    }

image

Ealier Code

plugin.Register(pluginEvents, proxyContext, pluginUrls ?? defaultUrlsToWatch, h.ConfigSection is null ? null : Configuration.GetSection(h.ConfigSection));

Changes Made:

plugin.Register(
    pluginEvents,
    proxyContext,
    (pluginUrls != null && pluginUrls.Count > 0) ? pluginUrls : defaultUrlsToWatch,
    h.ConfigSection is null ? null : Configuration.GetSection(h.ConfigSection)
);

…n-empty 'pluginUrls'. This ensures proper handling of empty plugin URL arrays and aligns with the requirement outlined in the issue. Updated the 'Register' method call to conditionally use 'pluginUrls' or default to 'defaultUrlsToWatch' based on the not null and not empty check. dotnet#528
This commit addresses the issue where plugins defining an empty array for 'urlsToWatch' would result in the plugin being disabled. The code has been modified to check for both null and empty arrays, and in both cases, it now defaults to using the global list of URLs. This ensures that plugins remain active even when no specific URLs are provided.
@SilentSobs SilentSobs requested a review from a team January 29, 2024 01:23
Copy link
Collaborator

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

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

Almost there. Let's do one small adjustment and we'll merge it in. We appreciate your help

@waldekmastykarz waldekmastykarz merged commit 361a0df into dotnet:main Jan 29, 2024
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.

When plugin defines an empty array of URLs to watch, use the global one
2 participants