A failed notebook can fail for very different reasons: the session never started, the capacity is full, your code has a bug, the data does not match the table, or an executor ran out of memory. Good troubleshooting means sorting the failure into a family first, then using the right evidence.
Where the evidence is
- Inside the notebook. The cell output shows the Python or Spark exception. The notebook's contextual monitoring shows jobs, stages, tasks and executors per cell, and the Spark advisor gives hints about the code that ran.
- Monitor hub. Open the Spark application to see its jobs, resource use and logs. The Logs tab offers driver, Livy and prelaunch logs that you can search and download.
- Spark UI. Reached from the application's Jobs tab. The Stages tab shows per-task duration and data size, which reveals skew. Executors shows memory and exit codes, Storage shows cached data, and Environment shows the active configuration.
- History server. For finished applications; its Diagnosis tab analyses data skew, time skew and executor usage.
- From a pipeline. A notebook activity has a deep link to the application and shows the inline error, so you can start from the failed pipeline run.
Always read the full stack trace. Spark wraps the real cause: a "job aborted" message, for example, usually contains the task exception that actually failed.
The error families
1. Permissions and capacity
- A 403 or "not authorized" error means the identity running the notebook lacks rights. Check the workspace role (Contributor or higher is needed for most work, Viewer is limited), the item permissions on the lakehouse (Read, ReadData or ReadAll), and storage roles when you read through a path.
- HTTP 430 means the capacity has hit its Spark compute limit, so the job cannot start. Free capacity, stagger the jobs, or move to a larger capacity.
- HTTP 429 is an API rate limit. Add retries with exponential back-off.
2. Session and configuration
- The session fails to start within the timeout: the cluster has too few resources, or a custom environment with many or large libraries takes too long to build. Remove libraries to isolate the cause.
- A session killed right at startup is often an invalid Spark setting, for example a message-size property written with a unit suffix when a plain integer is required. Review the
%%configurecell and remove recent settings. - Settings for executor and driver resources are read when the session starts, so set them with
%%configureat the top of the notebook rather than withspark.conf.set()later.
3. Code and data
- A
NullPointerExceptionoften comes from null values reaching a UDF. Filter nulls first or make the UDF null safe. - A Delta write that fails with a data transformation error usually has a schema or quality cause: nulls in a non-nullable column, a type mismatch, or a value outside a constraint. Compare schemas before writing:
from pyspark.sql.functions import col
df.printSchema()
spark.sql("DESCRIBE EXTENDED target_table").show(truncate=False)
df = df.filter(col("required_col").isNotNull())
ModuleNotFoundErrorin the driver stderr means a library is missing from the environment.- A streaming query exception wraps another error; check source and sink availability and that the checkpoint is valid. A corrupted checkpoint may force a restart from scratch.
- A behavior change after upgrading the runtime (
INCONSISTENT_BEHAVIOR_CROSS_VERSION) often points at date and timestamp handling in Parquet. Test any rebase setting on a sample before using it in production.
4. Memory
Out-of-memory failures show up as lost executors and an exit code in the Spark UI Executors tab.
- 137 means the container was killed for exceeding its memory limit, usually from skew, huge partitions, over-caching, a large broadcast or Python UDFs.
- 143 is a graceful termination. Dynamic allocation scales idle executors down this way, so it is often harmless when the job finishes. During active work it points to a heartbeat timeout, preemption or scale-down.
- The
MaxExecutorFailuresmessage is a symptom, not the cause: find out why the executors failed.
Remedies for 137: raise executor memory and overhead through %%configure, repartition into smaller even partitions (aim for roughly 128 to 256 MB each), keep adaptive query execution and skew-join handling on, cache less and unpersist when finished, and turn off broadcast for large tables.
A quick routine
- Open the failed run and read the first real error, not the final wrapper.
- Classify it: access, capacity, session, code or data, memory.
- Pick the evidence: driver log for startup and code errors, Executors tab for exit codes, Stages tab for skew.
- Change one thing and rerun on a small sample.
For the exam
- Use the Monitor hub, Spark UI, driver logs and history server; the Stages tab shows skew.
- Exit code 137 means out of memory; 143 is often normal scale-down.
- HTTP 430 is a capacity limit; HTTP 429 is rate limiting that needs back-off.
- Set resource configuration with
%%configure, not laterspark.conf.set()calls. - Read the whole stack trace: the first line is often only a wrapper.