Use it when the symptom is “Script Failure”: work through the layers in order and stop at the first one that fails.
Script Failure
Script Failure isolates interpreter, parsing, control-flow, dependency, command-execution and exit-status failures in a specific script invocation without assuming the last printed error is the root cause.
1. Script failure: read the error and exit code.
2. Trace execution.
3. Compare environments (interactive vs scheduler).
4. Check inputs.
5. Fix and add test.
script → error → trace → fix
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
python -c "import ast,pathlib; ast.parse(pathlib.Path('<script.py>').read_text())"Primary Commands
Configuration and operational commands for this Topic.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
invocation → script revision → interpreter/environment → input validation → parse/control flow → function/module → child command/API → exit/exception → partial target state → acceptance test
Healthy evidence: script revision and runtime context are pinned, the first exception/exit boundary is reproducible, partial effects are known, and the corrected invocation passes target read-back and acceptance.
Step 2 Telling causes apart Verify boundary
Known-good begins with the AST parse completing successfully (process exit code 0) for the intended source revision, then the original script invocation completing with the expected exit code/output and target state. Broken state is a deterministic SyntaxError/parse failure or a clean parse followed by a repeatable runtime boundary failure. AST success shows Python syntax only, but it does not show imports, runtime logic, credentials or downstream operations.
Step 3 Common mistakes Verify boundary
- Reading only the last log line.
- Re-running without understanding what already changed.
Step 4 Verification path Verify boundary
To verify Script Failure, first record run/request/job ID, definition revision, target identity, attempt number, timestamp and correlation/error identifier. Then check the result reported by the tool, and finally read the concrete target state and the earliest subsystem that can show or disprove the failure hypothesis directly and compare it with what you intended.
Also test the cases that usually go wrong: blind retry loops, overwriting the first error, widening privileges, conflating timeout with non-execution, hiding partial success and treating a controller status as target-evidence of the actual state.
Step 5 Failure modes and next checks Narrow the fault
Suspicious evidence: only a generic job error is available, the script changed between attempts, environment differences are ignored, or partial side effects are never inspected.
Step 6 Observation-driven branch and next-check logic Narrow the fault
First preserve the exact invocation, input and error/exit code. Run python -c "import ast,pathlib; ast.parse(pathlib.Path('<script.py>').read_text())" against the same source revision. If parsing fails, correct the reported syntax location before investigating runtime; if parsing succeeds, reproduce with the same interpreter/environment and inspect imports, input validation and the first failing external boundary. If an external command fails, record its exit code/stdout/stderr rather than masking it with generic exception handling.
Step 7 Where it fails Narrow the fault
Typical problems with Script Failure: blind retry loops, overwriting the first error, widening privileges, conflating timeout with non-execution, hiding partial success and treating a controller status as target-evidence of the actual state.
Before you retry a change, read the target's current state first, using run/request/job ID, definition revision, target identity, attempt number, timestamp and correlation/error identifier.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Non-zero exit ≠ no target-side changes occurred.
- Last stack-frame message ≠ earliest causal failure.
- Script runs interactively ≠ automation invocation has identical environment.
- Exit code 0 ≠ desired state verified.
bash -x script.sh / Set-PSDebug -Trace 1 / python3 -m pdb— trace- Exit code and stderr — error
- Environment differences (PATH, user, cwd) — context
ReferenceWhat it is1 section · depth on demand
Core model
Pin script content/hash, interpreter/version, invocation, parameters, environment and working directory; reproduce with the same inputs; identify parse/runtime/function/module/child-process boundary; capture stderr, exception stack and exit code; inspect any partial side effects; fix the earliest defect; rerun with original inputs and verify target state.
ReferenceHow it works2 sections · depth on demand
How it works and how it fails
Script Failure can originate before execution (parse/load), during dependency/import resolution, inside business logic, or from an external command/API invoked by the script. Python's AST parser owns only syntax validity for a selected source file; runtime environment, inputs and side effects are separate stages. A script that parses cleanly can still fail on imports, permissions, data shape or downstream service state.
In depth
A script failure is a non-zero exit, an unhandled exception or wrong output from a script. The cause is usually in the input, the environment the script ran in, or an external dependency.
| Check | Command |
|---|---|
| Exit code | echo $?, $LASTEXITCODE |
| Full error | Last 50 lines of the log, stack trace |
| Environment | Interpreter version, PATH, user |
| Trace | bash -x, Set-PSDebug -Trace 1, python -m pdb |
Reproduce with the exact same inputs and user; most "works for me" cases are environment differences.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A script error shows only the observed invocation failed at or after a recorded boundary, but it does not show earlier operations were rolled back or that later targets were untouched.
Mechanics
Durable intent is a bounded diagnostic hypothesis tied to stable run/request/target identity and the earliest observable failing layer; stable identity is run/request/job ID, definition revision, target identity, attempt number, timestamp and correlation/error identifier. The consumer-visible target is the concrete target state and the earliest subsystem that can show or disprove the failure hypothesis. The operating invariants are that the first concrete error is preserved, retries are safe and bounded, unknown completion is distinguished from failure, and final state is re-read independently. Follow the chain of components input/selection → controller/scheduler → worker/executor → transport/provider → target subsystem → consumer-visible state → independent read-back and record which layer currently owns truth.
ReferenceConfiguration & state1 section · depth on demand
Lifecycle
A fresh noninteractive execution should be reproducible from source-controlled intent plus documented prerequisites, and the release must retain enough identity to tie every result back to run/request/job ID, definition revision, target identity, attempt number, timestamp and correlation/error identifier.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Automation Troubleshooting > Script Failure. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/azure/architecture/patterns/retry · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Script Failure troubleshooting proof-boundary map
Fast symptom/scope, first-failed-boundary, effective-outcome and recovery/closure map for Script Failure.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Symptom / scope | Time window, immutable source/run identity, effective inputs and exact targets are explicit | Floating source, changed inputs or ambiguous targets destroy reproducibility |
| First failed boundary | Transport/auth/dependency/render/operation evidence identifies the earliest divergence | Investigation starts at the final error and skips earlier unproven boundaries |
| Effective outcome | Controller result is paired with target read-back and workload/service acceptance | Green execution state or changed symptom substitutes for effective-state verification |
| Recovery / closure | Minimal change restores the original test and regression/partial-state checks are clean | Broad retry or unrelated edits make the incident non-reproducible and hide residual state |
Deep reference
Healthy vs suspicious evidence
Output interpretation
Capture at minimum run/request ID, target ID, attempt, stage/boundary, status, error class/code/message, timestamps, partial-success set and independent final-state observation.