Home / Function/ error() — svelte Function Reference

error() — svelte Function Reference

Architecture documentation for the error() function in boundary.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  4eea2345_5d26_6ea8_43e3_80ca7101b747["error()"]
  928abd29_a193_3303_bc6d_b7d6ce0b17ec["Boundary"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|defined in| 928abd29_a193_3303_bc6d_b7d6ce0b17ec
  e4353d76_4179_4130_6f86_2b16446a2767["constructor()"]
  e4353d76_4179_4130_6f86_2b16446a2767 -->|calls| 4eea2345_5d26_6ea8_43e3_80ca7101b747
  faf0e92f_7626_2d66_f7f8_05458f022351["branch()"]
  faf0e92f_7626_2d66_f7f8_05458f022351 -->|calls| 4eea2345_5d26_6ea8_43e3_80ca7101b747
  eda2a5e7_3416_168e_40ff_8ceab3099f6c["has_pending_snippet()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| eda2a5e7_3416_168e_40ff_8ceab3099f6c
  410f774f_2d1a_7114_fcba_b292ed7cae3a["destroy_effect()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 410f774f_2d1a_7114_fcba_b292ed7cae3a
  40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 40f27ad3_30bb_8f2a_3fb3_757088cf7428
  f9ae9319_6a9b_3f6e_0878_87009a10797e["next()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| f9ae9319_6a9b_3f6e_0878_87009a10797e
  8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e["skip_nodes()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e
  2db52f34_d1ab_fc19_7dee_c08fdf752938["svelte_boundary_reset_noop()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 2db52f34_d1ab_fc19_7dee_c08fdf752938
  6a40527b_ca35_3e05_733a_42a463b9534d["svelte_boundary_reset_onerror()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 6a40527b_ca35_3e05_733a_42a463b9534d
  2ec0d2fd_8bbc_b2ba_53ae_f2da02bb3ba5["ensure()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 2ec0d2fd_8bbc_b2ba_53ae_f2da02bb3ba5
  27507f0c_dcab_c3a5_2ce6_5e4b1ef9df3d["pause_effect()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 27507f0c_dcab_c3a5_2ce6_5e4b1ef9df3d
  faf0e92f_7626_2d66_f7f8_05458f022351["branch()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| faf0e92f_7626_2d66_f7f8_05458f022351
  2cab0f64_6d19_d981_66e2_d2555c252702["queue_micro_task()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 2cab0f64_6d19_d981_66e2_d2555c252702
  623c7d5f_8856_1cec_42aa_d58e310da5d1["invoke_error_boundary()"]
  4eea2345_5d26_6ea8_43e3_80ca7101b747 -->|calls| 623c7d5f_8856_1cec_42aa_d58e310da5d1
  style 4eea2345_5d26_6ea8_43e3_80ca7101b747 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/blocks/boundary.js lines 380–484

	error(error) {
		var onerror = this.#props.onerror;
		let failed = this.#props.failed;

		// If we have nothing to capture the error, or if we hit an error while
		// rendering the fallback, re-throw for another boundary to handle
		if (this.#is_creating_fallback || (!onerror && !failed)) {
			throw error;
		}

		if (this.#main_effect) {
			destroy_effect(this.#main_effect);
			this.#main_effect = null;
		}

		if (this.#pending_effect) {
			destroy_effect(this.#pending_effect);
			this.#pending_effect = null;
		}

		if (this.#failed_effect) {
			destroy_effect(this.#failed_effect);
			this.#failed_effect = null;
		}

		if (hydrating) {
			set_hydrate_node(/** @type {TemplateNode} */ (this.#hydrate_open));
			next();
			set_hydrate_node(skip_nodes());
		}

		var did_reset = false;
		var calling_on_error = false;

		const reset = () => {
			if (did_reset) {
				w.svelte_boundary_reset_noop();
				return;
			}

			did_reset = true;

			if (calling_on_error) {
				e.svelte_boundary_reset_onerror();
			}

			// If the failure happened while flushing effects, current_batch can be null
			Batch.ensure();

			this.#local_pending_count = 0;

			if (this.#failed_effect !== null) {
				pause_effect(this.#failed_effect, () => {
					this.#failed_effect = null;
				});
			}

			// we intentionally do not try to find the nearest pending boundary. If this boundary has one, we'll render it on reset
			// but it would be really weird to show the parent's boundary on a child reset.
			this.is_pending = this.has_pending_snippet();

			this.#main_effect = this.#run(() => {
				this.#is_creating_fallback = false;
				return branch(() => this.#children(this.#anchor));
			});

			if (this.#pending_count > 0) {
				this.#show_pending_snippet();
			} else {
				this.is_pending = false;
			}
		};

		queue_micro_task(() => {
			try {
				calling_on_error = true;
				onerror?.(error, reset);
				calling_on_error = false;
			} catch (error) {
				invoke_error_boundary(error, this.#effect && this.#effect.parent);
			}

Domain

Subdomains

Frequently Asked Questions

What does error() do?
error() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/blocks/boundary.js.
Where is error() defined?
error() is defined in packages/svelte/src/internal/client/dom/blocks/boundary.js at line 380.
What does error() call?
error() calls 12 function(s): branch, destroy_effect, ensure, has_pending_snippet, invoke_error_boundary, next, pause_effect, queue_micro_task, and 4 more.
What calls error()?
error() is called by 2 function(s): branch, constructor.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free