Skip to content

Conversation

@oshezaf
Copy link
Contributor

@oshezaf oshezaf commented Jan 10, 2026

See readme file for details about this new tool

try:
cache_file.unlink()
count += 1
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 3 days ago

In general, empty except blocks should either (a) handle the exception in a meaningful way (logging, cleanup, fallback logic) or (b) clearly document why it is safe to ignore the exception. For non-critical operations like cache cleanup, the usual best practice is to log the error at a low severity (e.g., debug/warning) and continue.

For this specific case in clear_cache, we want to keep the behavior that cache deletion failures are non-fatal, but avoid completely silent suppression. The best minimally invasive fix is to catch Exception as exc, add a short explanatory comment that failures are non-fatal, and optionally emit a debug message to stderr using only the existing sys import (to avoid introducing new dependencies or changing existing imports). We should not raise the exception, because that would change the behavior of clear_cache and could break callers that assume it never raises.

Concretely:

  • In Tools/TableViewGenerator/deploy_table_views.py, within clear_cache, replace the except Exception: / pass block around cache_file.unlink() with an except Exception as exc: block that writes a brief debug message to sys.stderr (including the filename) and includes a comment explaining that cache deletion failures are non-fatal and therefore only logged.
  • No new imports or functions are needed; the file already imports sys.
Suggested changeset 1
Tools/TableViewGenerator/deploy_table_views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tools/TableViewGenerator/deploy_table_views.py b/Tools/TableViewGenerator/deploy_table_views.py
--- a/Tools/TableViewGenerator/deploy_table_views.py
+++ b/Tools/TableViewGenerator/deploy_table_views.py
@@ -113,8 +113,9 @@
         try:
             cache_file.unlink()
             count += 1
-        except Exception:
-            pass
+        except Exception as exc:
+            # Cache deletion failures are non-fatal; log and continue.
+            print(f"Warning: failed to delete cache file {cache_file}: {exc}", file=sys.stderr)
     return count
 
 
EOF
@@ -113,8 +113,9 @@
try:
cache_file.unlink()
count += 1
except Exception:
pass
except Exception as exc:
# Cache deletion failures are non-fatal; log and continue.
print(f"Warning: failed to delete cache file {cache_file}: {exc}", file=sys.stderr)
return count


Copilot is powered by AI and may make mistakes. Always verify output.
try:
ws_idx = parts.index('workspaces') + 1
workspace_name = parts[ws_idx]
except (ValueError, IndexError):

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 3 days ago

In general, to fix an empty except block, you either narrow the exception and handle it appropriately (e.g., log, adjust state, recover) or remove the try/except if failure is acceptable and should raise. Where failure is truly optional, you should still document that explicitly, typically with a short comment or a log message.

Here, the best fix that preserves existing functionality is to keep the “best effort” nature (do not exit or re-raise) but add minimal handling inside the except block. We can either:

  • Log a brief message explaining that the workspace name could not be parsed from resource_id, and that we’re continuing without it; or
  • At least add an explanatory comment so the intent is clear.

To add real handling without changing flow, we will print a short message to stderr when parsing fails, then proceed as before with workspace_name left as None. This adds observability while maintaining current behavior.

Concretely, in Tools/TableViewGenerator/deploy_table_views.py around lines 730–736, we will replace:

    if not workspace_name:
        parts = args.resource_id.split('/')
        try:
            ws_idx = parts.index('workspaces') + 1
            workspace_name = parts[ws_idx]
        except (ValueError, IndexError):
            pass

with code that prints a non-fatal warning in the except block. No new imports or helpers are needed, since sys is already imported at the top.

Suggested changeset 1
Tools/TableViewGenerator/deploy_table_views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tools/TableViewGenerator/deploy_table_views.py b/Tools/TableViewGenerator/deploy_table_views.py
--- a/Tools/TableViewGenerator/deploy_table_views.py
+++ b/Tools/TableViewGenerator/deploy_table_views.py
@@ -733,7 +733,8 @@
             ws_idx = parts.index('workspaces') + 1
             workspace_name = parts[ws_idx]
         except (ValueError, IndexError):
-            pass
+            # Best-effort parsing of workspace name; continue without it if parsing fails
+            print("Warning: Could not parse workspace name from resource ID; continuing without workspace name.", file=sys.stderr)
     
     print("\n==========================================")
     print("   Deploy Table Views to Log Analytics    ")
EOF
@@ -733,7 +733,8 @@
ws_idx = parts.index('workspaces') + 1
workspace_name = parts[ws_idx]
except (ValueError, IndexError):
pass
# Best-effort parsing of workspace name; continue without it if parsing fails
print("Warning: Could not parse workspace name from resource ID; continuing without workspace name.", file=sys.stderr)

print("\n==========================================")
print(" Deploy Table Views to Log Analytics ")
Copilot is powered by AI and may make mistakes. Always verify output.
import argparse
import hashlib
import json
import os

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'os' is not used.

Copilot Autofix

AI 3 days ago

To fix an unused import, the general approach is to remove the import statement for the unused module, provided that the module is not referenced anywhere in the file. This eliminates an unnecessary dependency and makes the code clearer.

For this specific case in Tools/TableViewGenerator/generate_table_views_templates.py, the best fix is to delete the import os line (line 21) and leave all other imports and code unchanged. No additional methods, imports, or definitions are required. This change should be applied only to the single line that imports os, keeping the surrounding import block intact.

Suggested changeset 1
Tools/TableViewGenerator/generate_table_views_templates.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tools/TableViewGenerator/generate_table_views_templates.py b/Tools/TableViewGenerator/generate_table_views_templates.py
--- a/Tools/TableViewGenerator/generate_table_views_templates.py
+++ b/Tools/TableViewGenerator/generate_table_views_templates.py
@@ -18,7 +18,6 @@
 import argparse
 import hashlib
 import json
-import os
 import re
 import sys
 from dataclasses import dataclass, field
EOF
@@ -18,7 +18,6 @@
import argparse
import hashlib
import json
import os
import re
import sys
from dataclasses import dataclass, field
Copilot is powered by AI and may make mistakes. Always verify output.
try:
cache_file.unlink()
count += 1
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 3 days ago

In general, to fix empty except blocks you either (a) add appropriate handling (logging, cleanup, fallback) or (b) add a clear explanatory comment if ignoring the error is truly intentional and safe.

For this file, the best minimal fix without changing existing functionality is to keep ignoring deletion errors from cache_file.unlink() but add a brief comment explaining they are non-fatal, mirroring the pattern used in _write_to_cache. This satisfies CodeQL (the block is no longer "does nothing" and/or has an explanatory comment) and clarifies the intent for future maintainers. We should only modify the except Exception: block inside clear_cache at lines 114–118 in Tools/TableViewGenerator/generate_table_views_templates.py. No new imports or helper methods are required.

Suggested changeset 1
Tools/TableViewGenerator/generate_table_views_templates.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tools/TableViewGenerator/generate_table_views_templates.py b/Tools/TableViewGenerator/generate_table_views_templates.py
--- a/Tools/TableViewGenerator/generate_table_views_templates.py
+++ b/Tools/TableViewGenerator/generate_table_views_templates.py
@@ -115,6 +115,7 @@
             cache_file.unlink()
             count += 1
         except Exception:
+            # Cache delete failures are non-fatal; ignore and continue
             pass
     return count
 
EOF
@@ -115,6 +115,7 @@
cache_file.unlink()
count += 1
except Exception:
# Cache delete failures are non-fatal; ignore and continue
pass
return count

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants