-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Asim/generate test views #13420
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
base: master
Are you sure you want to change the base?
Asim/generate test views #13420
Conversation
For testing parsers
| try: | ||
| cache_file.unlink() | ||
| count += 1 | ||
| except Exception: |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
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, withinclear_cache, replace theexcept Exception:/passblock aroundcache_file.unlink()with anexcept Exception as exc:block that writes a brief debug message tosys.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.
-
Copy modified lines R116-R118
| @@ -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 | ||
|
|
||
|
|
| try: | ||
| ws_idx = parts.index('workspaces') + 1 | ||
| workspace_name = parts[ws_idx] | ||
| except (ValueError, IndexError): |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
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):
passwith 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.
-
Copy modified lines R736-R737
| @@ -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 ") |
| import argparse | ||
| import hashlib | ||
| import json | ||
| import os |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -18,7 +18,6 @@ | ||
| import argparse | ||
| import hashlib | ||
| import json | ||
| import os | ||
| import re | ||
| import sys | ||
| from dataclasses import dataclass, field |
| try: | ||
| cache_file.unlink() | ||
| count += 1 | ||
| except Exception: |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R118
| @@ -115,6 +115,7 @@ | ||
| cache_file.unlink() | ||
| count += 1 | ||
| except Exception: | ||
| # Cache delete failures are non-fatal; ignore and continue | ||
| pass | ||
| return count | ||
|
|
See readme file for details about this new tool