From ce79b603166f4da9d208fcc8f55c08c9f72c1c33 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:41:05 +0000 Subject: [PATCH] refactor: share one exception constructor and text reader across the Python bindings The binding crates built their error-class exceptions and read optional text values with about forty private copies of the same few lines. - Add exception_from to the records construct helpers. new_error now takes optional code and help keywords, replacing new_helped_error; new_plain_error and host_error delegate to it, and each command's error wrapper is one call. - Add the base readers optional_text (a str value or None) and text_item (a dict item as optional text). They replace the per-crate dict readers, the compile setup and planner envelope readers, and the execution history reader. The strict None-or-str readers in compile targets and execution history are renamed nullable_text so the two meanings no longer share a name. - Drop the scoped dupes allowlist entries for these clusters, give the dbt manifest-object and argv builders their own entries, and lower the Python-crossing budgets and the sqlbuild-python line cap to the new counts. --- .../src/boundary/main/mod.rs | 2 + .../src/boundary/main/optional_text.rs | 12 +++ .../src/boundary/main/text_item.rs | 13 +++ .../src/native_host/_helpers/host.rs | 7 -- .../src/native_host/main/host_error.rs | 6 +- .../_helpers/native_classes/construct.rs | 64 ++++++------- .../records/main/construct/exception_from.rs | 14 +++ .../src/records/main/construct/mod.rs | 2 +- .../src/records/main/construct/new_error.rs | 13 ++- .../main/construct/new_helped_error.rs | 17 ---- .../_helpers/setup/relation_targets.rs | 12 +-- .../compile_driver/_helpers/setup/targets.rs | 33 +++---- .../main/setup/managed_write_schema.rs | 5 +- .../main/setup/preserved_loader_schemas.rs | 6 +- .../input_loops/_helpers/model/model_loop.rs | 25 +---- .../_helpers/model/model_loop_host.rs | 6 +- .../_helpers/model_loop/model_loop_opt_out.rs | 29 +++--- .../_helpers/resources/audit_loop.rs | 13 +-- .../resources/resource_diagnostics.rs | 14 +-- .../_helpers/syntax_validation.rs | 18 ++-- .../_helpers/checking/native_header_parser.rs | 19 ++-- .../_helpers/config_validation.rs | 13 +-- .../_helpers/expansion/macro_expansion.rs | 8 +- .../_helpers/sql_macros/sql_macro_host.rs | 8 +- .../sql_macros/sql_macro_inventory.rs | 8 +- .../_helpers/event_rows/freshness.rs | 6 +- .../_helpers/tables/state_tables.rs | 15 ++- .../lifecycle_events/_helpers/envelopes.rs | 26 ++---- .../plan_output/_helpers/python_identity.rs | 17 +--- .../compiled_project/main/materialization.rs | 4 +- .../src/compiled_project/main/mod.rs | 1 - .../src/compiled_project/main/model_facts.rs | 6 +- .../src/compiled_project/main/text_value.rs | 12 --- .../compiled_models/compiled_model_view.rs | 18 +--- .../_helpers/python_nodes/python_selection.rs | 20 ++-- .../references/_helpers/source_relations.rs | 30 ++---- .../_helpers/build_command/policies.rs | 18 ++-- .../bindings/_helpers/check/check_command.rs | 12 +-- .../src/bindings/_helpers/cli/dispatch.rs | 18 ++-- .../src/bindings/_helpers/cli/entry.rs | 4 +- .../bindings/_helpers/clone/clone_command.rs | 12 +-- .../_helpers/contract_command/command.rs | 12 +-- .../bindings/_helpers/cost_command/refusal.rs | 20 ++-- .../src/bindings/_helpers/dbt_command/init.rs | 21 ++--- .../_helpers/dbt_command/init_project.rs | 6 +- .../src/bindings/_helpers/dbt_interop/cli.rs | 18 +--- .../bindings/_helpers/dbt_interop/graph.rs | 18 ++-- .../bindings/_helpers/dbt_interop/manifest.rs | 17 ++-- .../bindings/_helpers/diff_report/support.rs | 18 ++-- .../_helpers/execution_history/conversion.rs | 37 +++----- .../_helpers/execution_history/functions.rs | 9 +- .../_helpers/execution_history/postgres.rs | 24 ++--- .../_helpers/execution_history/sqlite.rs | 26 +++--- .../_helpers/format_command/selection.rs | 14 +-- .../_helpers/freshness/freshness_command.rs | 12 +-- .../bindings/_helpers/init_command/command.rs | 14 +-- .../_helpers/janitor/janitor_command.rs | 17 ++-- .../_helpers/lineage/lineage_command.rs | 17 ++-- .../bindings/_helpers/load/load_selection.rs | 34 +++---- .../bindings/_helpers/query_command/query.rs | 16 +--- .../src/bindings/_helpers/recall/command.rs | 2 +- .../_helpers/refactor/refactor_command.rs | 17 ++-- .../_helpers/review_command/comparison.rs | 4 +- .../_helpers/review_command/planning.rs | 14 +-- .../_helpers/review_command/support.rs | 24 ++--- .../_helpers/scenario_command/setup.rs | 18 ++-- .../_helpers/sql_test_command/python_tests.rs | 21 +++-- .../_helpers/sql_test_command/test_command.rs | 40 ++++---- .../_helpers/sql_test_command/timeouts.rs | 7 +- fensu.toml | 91 ++++++++----------- 70 files changed, 466 insertions(+), 708 deletions(-) create mode 100644 crates/sqlbuild-python-base/src/boundary/main/optional_text.rs create mode 100644 crates/sqlbuild-python-base/src/boundary/main/text_item.rs create mode 100644 crates/sqlbuild-python-base/src/records/main/construct/exception_from.rs delete mode 100644 crates/sqlbuild-python-base/src/records/main/construct/new_helped_error.rs delete mode 100644 crates/sqlbuild-python-project/src/compiled_project/main/text_value.rs diff --git a/crates/sqlbuild-python-base/src/boundary/main/mod.rs b/crates/sqlbuild-python-base/src/boundary/main/mod.rs index 0386ce48a9..a4691e03d7 100644 --- a/crates/sqlbuild-python-base/src/boundary/main/mod.rs +++ b/crates/sqlbuild-python-base/src/boundary/main/mod.rs @@ -8,9 +8,11 @@ pub mod imported; pub mod json_value_to_python; pub mod keywords; pub mod native_compiler_error; +pub mod optional_text; pub mod register_expected_errors; pub mod register_native_compiler_error; pub mod register_oracles; +pub mod text_item; pub mod utf16_units; pub mod value_error; pub mod within; diff --git a/crates/sqlbuild-python-base/src/boundary/main/optional_text.rs b/crates/sqlbuild-python-base/src/boundary/main/optional_text.rs new file mode 100644 index 0000000000..a682e1e98f --- /dev/null +++ b/crates/sqlbuild-python-base/src/boundary/main/optional_text.rs @@ -0,0 +1,12 @@ +//! `value` as text when it is a `str`, else `None`. + +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult}; +use pyo3::types::PyString; + +/// `value` as text when it is a `str`, else `None`. +pub fn optional_text(value: &Bound<'_, PyAny>) -> PyResult> { + if value.is_instance_of::() { + return Ok(Some(value.extract()?)); + } + Ok(None) +} diff --git a/crates/sqlbuild-python-base/src/boundary/main/text_item.rs b/crates/sqlbuild-python-base/src/boundary/main/text_item.rs new file mode 100644 index 0000000000..187cf06388 --- /dev/null +++ b/crates/sqlbuild-python-base/src/boundary/main/text_item.rs @@ -0,0 +1,13 @@ +//! `values[key]` as text when it is present and a `str`, else `None`. + +use crate::boundary::main::optional_text::optional_text; +use pyo3::prelude::{Bound, PyResult}; +use pyo3::types::{PyDict, PyDictMethods}; + +/// `values[key]` as text when it is present and a `str`, else `None`. +pub fn text_item(values: &Bound<'_, PyDict>, key: &str) -> PyResult> { + match values.get_item(key)? { + Some(value) => optional_text(&value), + None => Ok(None), + } +} diff --git a/crates/sqlbuild-python-base/src/native_host/_helpers/host.rs b/crates/sqlbuild-python-base/src/native_host/_helpers/host.rs index dfa367e8b4..dfd6cf90cb 100644 --- a/crates/sqlbuild-python-base/src/native_host/_helpers/host.rs +++ b/crates/sqlbuild-python-base/src/native_host/_helpers/host.rs @@ -138,10 +138,3 @@ pub(crate) fn within_identity_pass<'py, T>( let identity_pass: Bound<'py, PyAny> = entry(py, UserCodeHost::PythonIdentityPass)?.call0()?; within(&identity_pass, |_| body()) } - -/// The host exception class `id` raised with `message`, or the error looking it up or raising it. -pub(crate) fn host_error(py: Python<'_>, id: impl Into, message: &str) -> PyErr { - entry(py, id) - .and_then(|class| class.call1((message,))) - .map_or_else(|error| error, PyErr::from_value) -} diff --git a/crates/sqlbuild-python-base/src/native_host/main/host_error.rs b/crates/sqlbuild-python-base/src/native_host/main/host_error.rs index b6d9fbe0d3..8e8b6256a7 100644 --- a/crates/sqlbuild-python-base/src/native_host/main/host_error.rs +++ b/crates/sqlbuild-python-base/src/native_host/main/host_error.rs @@ -1,12 +1,12 @@ //! The host exception class `id` raised with `message`, or the error looking it up or raising it. -use crate::native_host::_helpers::host; +use crate::native_host::_helpers::host::entry; +use crate::records::main::construct::exception_from::exception_from; use pyo3::PyErr; use pyo3::prelude::Python; use sqlbuild_host::entries::models::HostId; /// The host exception class `id` raised with `message`, or the error looking it up or raising it. -#[inline] pub fn host_error(py: Python<'_>, id: impl Into, message: &str) -> PyErr { - host::host_error(py, id, message) + exception_from(entry(py, id), message, (None, None)) } diff --git a/crates/sqlbuild-python-base/src/records/_helpers/native_classes/construct.rs b/crates/sqlbuild-python-base/src/records/_helpers/native_classes/construct.rs index c87c99f7e1..d10b9621ac 100644 --- a/crates/sqlbuild-python-base/src/records/_helpers/native_classes/construct.rs +++ b/crates/sqlbuild-python-base/src/records/_helpers/native_classes/construct.rs @@ -43,22 +43,37 @@ pub(crate) fn error_class(py: Python<'_>, id: ErrorId) -> PyResult, id: ErrorId, message: &str) -> PyErr { - error_class(py, id) - .and_then(|class| class.call1((message,))) - .map_or_else(|error| error, PyErr::from_value) + new_error(py, id, message, (None, None)) } -/// A raisable native `id` error carrying `message` and the diagnostic `code`. -pub(crate) fn new_error(py: Python<'_>, id: ErrorId, message: String, code: &str) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - error_class(py, id)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } +/// The native `id` exception with `message` and the given `code` and `help`, or the error raising it. +pub(crate) fn new_error( + py: Python<'_>, + id: ErrorId, + message: &str, + keywords: (Option<&str>, Option<&str>), +) -> PyErr { + exception_from(error_class(py, id), message, keywords) +} + +/// The exception `class` with `message` and the given `code` and `help`, or the error raising it. +pub(crate) fn exception_from( + class: PyResult>, + message: &str, + (code, help): (Option<&str>, Option<&str>), +) -> PyErr { + class + .and_then(|class| { + let keywords: Bound<'_, PyDict> = PyDict::new(class.py()); + if let Some(code) = code { + keywords.set_item("code", code)?; + } + if let Some(help) = help { + keywords.set_item("help", help)?; + } + class.call((message,), Some(&keywords)) + }) + .map_or_else(|error| error, PyErr::from_value) } /// A raisable native `id` error carrying `message`, with each `(name, value)` attribute set on it. @@ -81,27 +96,6 @@ pub(crate) fn new_annotated_error( } } -/// A raisable native `id` error carrying `message`, the diagnostic `code` and optional `help`. -pub(crate) fn new_helped_error( - py: Python<'_>, - id: ErrorId, - (message, code): (String, &str), - help: Option<&str>, -) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - if let Some(help) = help { - options.set_item("help", help)?; - } - error_class(py, id)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } -} - /// The native record class or string enum `id` as registered, ignoring later attribute replacement. pub(crate) fn record_class(py: Python<'_>, id: RecordId) -> PyResult> { let classes: &Vec> = CLASSES diff --git a/crates/sqlbuild-python-base/src/records/main/construct/exception_from.rs b/crates/sqlbuild-python-base/src/records/main/construct/exception_from.rs new file mode 100644 index 0000000000..89a358f3e1 --- /dev/null +++ b/crates/sqlbuild-python-base/src/records/main/construct/exception_from.rs @@ -0,0 +1,14 @@ +//! The exception `class` with `message` and the given `code` and `help`. + +use crate::records::_helpers::native_classes::construct; +use pyo3::prelude::{Bound, PyAny, PyErr, PyResult}; + +/// The exception `class` with `message` and the given `code` and `help`, or the error raising it. +#[inline] +pub fn exception_from( + class: PyResult>, + message: &str, + keywords: (Option<&str>, Option<&str>), +) -> PyErr { + construct::exception_from(class, message, keywords) +} diff --git a/crates/sqlbuild-python-base/src/records/main/construct/mod.rs b/crates/sqlbuild-python-base/src/records/main/construct/mod.rs index fb2bfee1e3..393ad76d31 100644 --- a/crates/sqlbuild-python-base/src/records/main/construct/mod.rs +++ b/crates/sqlbuild-python-base/src/records/main/construct/mod.rs @@ -1,9 +1,9 @@ pub mod enum_from_value; pub mod enum_member; pub mod error_class; +pub mod exception_from; pub mod new_annotated_error; pub mod new_error; -pub mod new_helped_error; pub mod new_plain_error; pub mod new_record; pub mod new_record_with; diff --git a/crates/sqlbuild-python-base/src/records/main/construct/new_error.rs b/crates/sqlbuild-python-base/src/records/main/construct/new_error.rs index e78f77f5e5..c71783ee5c 100644 --- a/crates/sqlbuild-python-base/src/records/main/construct/new_error.rs +++ b/crates/sqlbuild-python-base/src/records/main/construct/new_error.rs @@ -1,12 +1,17 @@ -//! A raisable native `id` error carrying `message` and the diagnostic `code`. +//! The native `id` exception raised with `message` and the `code` and `help` keywords that are given. use crate::records::_helpers::native_classes::construct; use crate::records::types::ErrorId; use pyo3::prelude::PyErr; use pyo3::prelude::Python; -/// A raisable native `id` error carrying `message` and the diagnostic `code`. +/// The native `id` exception with `message` and the given `code` and `help`, or the error raising it. #[inline] -pub fn new_error(py: Python<'_>, id: ErrorId, message: String, code: &str) -> PyErr { - construct::new_error(py, id, message, code) +pub fn new_error( + py: Python<'_>, + id: ErrorId, + message: &str, + keywords: (Option<&str>, Option<&str>), +) -> PyErr { + construct::new_error(py, id, message, keywords) } diff --git a/crates/sqlbuild-python-base/src/records/main/construct/new_helped_error.rs b/crates/sqlbuild-python-base/src/records/main/construct/new_helped_error.rs deleted file mode 100644 index 552f712c73..0000000000 --- a/crates/sqlbuild-python-base/src/records/main/construct/new_helped_error.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! A raisable native `id` error carrying `message`, the diagnostic `code` and optional `help`. - -use crate::records::_helpers::native_classes::construct; -use crate::records::types::ErrorId; -use pyo3::prelude::PyErr; -use pyo3::prelude::Python; - -/// A raisable native `id` error carrying `message`, the diagnostic `code` and optional `help`. -#[inline] -pub fn new_helped_error( - py: Python<'_>, - id: ErrorId, - (message, code): (String, &str), - help: Option<&str>, -) -> PyErr { - construct::new_helped_error(py, id, (message, code), help) -} diff --git a/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs b/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs index 4ab615e5b5..c128f80344 100644 --- a/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs +++ b/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs @@ -3,6 +3,7 @@ use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::types::{PySet, PySetMethods, PyString}; use sqlbuild_host::entries::models::{AdapterHost, UserCodeHost}; +use sqlbuild_python_base::records::main::construct::exception_from::exception_from; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; @@ -33,12 +34,11 @@ impl<'py> RefKinds<'py> { /// A `SharedInputError` with `message`. fn shared_error(py: Python<'_>, message: String) -> PyErr { - match imported(py, SHARED_EXCEPTIONS_MODULE, "SharedInputError") - .and_then(|class| class.call1((message,))) - { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + exception_from( + imported(py, SHARED_EXCEPTIONS_MODULE, "SharedInputError"), + &message, + (None, None), + ) } /// The model, seed and Python source refs of a plan, as the frozenset Python builds. diff --git a/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs b/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs index 371073c49b..b7c74ca109 100644 --- a/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs +++ b/crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs @@ -3,6 +3,7 @@ use crate::compile_driver::main::setup::expanded_loader_namespace::expanded_loader_namespace; use crate::compile_driver::main::setup::managed_write_schema::managed_write_schema; use crate::compile_driver::models::TargetSettingsValues; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use std::collections::{HashMap, HashSet}; use pyo3::exceptions::PyException; @@ -92,27 +93,19 @@ pub(crate) fn planner_error( } /// `value` as an optional string: `None`, or a `str`'s text. -fn optional_text(value: &Bound<'_, PyAny>) -> PyResult> { +fn nullable_text(value: &Bound<'_, PyAny>) -> PyResult> { if value.is_none() { return Ok(None); } Ok(Some(value.extract()?)) } -/// `value` when it is a `str`, else `None`. -pub(crate) fn text_or_none(value: &Bound<'_, PyAny>) -> PyResult> { - match value.downcast::() { - Ok(text) => Ok(Some(text.to_cow()?.into_owned())), - Err(_) => Ok(None), - } -} - /// The connection's `part` when the compile leaves it unused because the project names connections or targets. fn ignored_connection_value(project: &Bound<'_, PyAny>, part: &str) -> PyResult> { - if text_or_none(&native_field(project, &format!("effective_target_{part}"))?)?.is_some() { + if optional_text(&native_field(project, &format!("effective_target_{part}"))?)?.is_some() { return Ok(None); } - text_or_none(&mapping_get( + optional_text(&mapping_get( &native_field(project, "effective_connection")?, part, )?) @@ -186,7 +179,7 @@ pub(crate) fn named_target_schema_strategy( if target_name.is_none() { return Ok(()); } - let schema: Option = text_or_none(&native_field(&target_config, "schema")?)?; + let schema: Option = optional_text(&native_field(&target_config, "schema")?)?; if schema.is_some_and(|schema| !python_strip(&schema).is_empty()) { return Ok(()); } @@ -198,7 +191,7 @@ pub(crate) fn named_target_schema_strategy( Some(cli_vars.clone()).filter(|value| !value.is_none()), false, )?; - let help: Option = match text_or_none(&mapping_get(&connection, "schema")?)? { + let help: Option = match optional_text(&mapping_get(&connection, "schema")?)? { Some(value) => { message.push_str(&ignored_connection_note("schema", &value)); Some(project_setting_help( @@ -336,7 +329,7 @@ fn target_namespaces( for item in mapping_items(&connection)?.try_iter()? { let item: Bound<'_, PyAny> = item?; let key: Bound<'_, PyAny> = item.get_item(0)?; - let Some(key) = text_or_none(&key)? else { + let Some(key) = optional_text(&key)? else { continue; }; if CONNECTION_IDENTITY_KEYS.contains(&key.as_str()) { @@ -476,7 +469,7 @@ pub(crate) fn validate_project_targets<'py>( /// Whether the adapter needs every model and seed database and schema resolved. pub(crate) fn requires_explicit_targets(adapter_name: &Bound<'_, PyAny>) -> PyResult { - Ok(text_or_none(adapter_name)? + Ok(optional_text(adapter_name)? .as_deref() .is_some_and(|name| EXPLICIT_TARGET_ADAPTERS.contains(&name))) } @@ -528,8 +521,8 @@ fn required_target_parts( project: &Bound<'_, PyAny>, ) -> PyResult<()> { let py: Python<'_> = target.py(); - let database: Option = optional_text(&native_field(target, "database")?)?; - let schema: Option = optional_text(&native_field(target, "schema")?)?; + let database: Option = nullable_text(&native_field(target, "database")?)?; + let schema: Option = nullable_text(&native_field(target, "schema")?)?; let missing: Vec<&str> = missing_target_parts(database.as_deref(), schema.as_deref()); let Some(first) = missing.first() else { return Ok(()); @@ -591,7 +584,7 @@ pub(crate) fn managed_write_schemas( return Ok(()); } let project_schema: Option = explicit_write_schema( - text_or_none(&native_field(project, "effective_target_schema")?)?.as_deref(), + optional_text(&native_field(project, "effective_target_schema")?)?.as_deref(), ); for (label, attribute) in [ ("Model", "models"), @@ -631,7 +624,7 @@ pub(crate) fn managed_write_schemas( let source_loaders: HashSet = managed_source_loaders(project)?; for loader in native_field(project, "loader_functions")?.try_iter()? { let loader: Bound<'_, PyAny> = loader?; - let destination: Option = text_or_none(&native_field(&loader, "destination")?)?; + let destination: Option = optional_text(&native_field(&loader, "destination")?)?; if destination.is_some_and(|destination| destination.contains('.')) || source_loaders.contains(&native_field(&loader, "name")?.extract::()?) { @@ -653,7 +646,7 @@ pub(crate) fn managed_write_schemas( pub(crate) fn managed_source_loaders(project: &Bound<'_, PyAny>) -> PyResult> { let mut loaders: HashSet = HashSet::new(); for source in native_field(project, "sources")?.try_iter()? { - if let Some(loader) = text_or_none(&native_field( + if let Some(loader) = optional_text(&native_field( &native_field(&source?, "source_entry")?, "loader", )?)? { diff --git a/crates/sqlbuild-python-compile/src/compile_driver/main/setup/managed_write_schema.rs b/crates/sqlbuild-python-compile/src/compile_driver/main/setup/managed_write_schema.rs index e61e725346..36989030cc 100644 --- a/crates/sqlbuild-python-compile/src/compile_driver/main/setup/managed_write_schema.rs +++ b/crates/sqlbuild-python-compile/src/compile_driver/main/setup/managed_write_schema.rs @@ -5,12 +5,12 @@ use crate::compile_driver::_helpers::setup::targets::DEFAULTS_SECTION; use crate::compile_driver::_helpers::setup::targets::ignored_connection_note; use crate::compile_driver::_helpers::setup::targets::planner_error; use crate::compile_driver::_helpers::setup::targets::project_setting_help; -use crate::compile_driver::_helpers::setup::targets::text_or_none; use pyo3::prelude::{Bound, PyAny, PyResult, Python}; use sqlbuild_analysis::assembly::target_checks::constants::MANAGED_WRITE_SCHEMA_CODE; use sqlbuild_analysis::assembly::target_checks::errors::TargetError; use sqlbuild_analysis::assembly::target_checks::main::explicit_write_schema::explicit_write_schema; use sqlbuild_analysis::assembly::target_checks::main::target_error_message::target_error_message; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; /// Raise when neither the resource nor the project names a physical write schema. pub fn managed_write_schema( @@ -18,7 +18,8 @@ pub fn managed_write_schema( schema: &Bound<'_, PyAny>, (project_schema, ignored): (Option<&str>, Option<&str>), ) -> PyResult<()> { - if explicit_write_schema(text_or_none(schema)?.as_deref()).is_some() || project_schema.is_some() + if explicit_write_schema(optional_text(schema)?.as_deref()).is_some() + || project_schema.is_some() { return Ok(()); } diff --git a/crates/sqlbuild-python-compile/src/compile_driver/main/setup/preserved_loader_schemas.rs b/crates/sqlbuild-python-compile/src/compile_driver/main/setup/preserved_loader_schemas.rs index c02dee4ac6..54162399ed 100644 --- a/crates/sqlbuild-python-compile/src/compile_driver/main/setup/preserved_loader_schemas.rs +++ b/crates/sqlbuild-python-compile/src/compile_driver/main/setup/preserved_loader_schemas.rs @@ -2,7 +2,6 @@ use crate::compile_attachment::main::resolved_target::resolved_target; use crate::compile_driver::_helpers::setup::targets::planner_error; -use crate::compile_driver::_helpers::setup::targets::text_or_none; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use sqlbuild_analysis::assembly::target_checks::constants::{ MANAGED_WRITE_SCHEMA_CODE, PRESERVE_TARGET_VALUE, @@ -10,6 +9,7 @@ use sqlbuild_analysis::assembly::target_checks::constants::{ use sqlbuild_analysis::assembly::target_checks::errors::TargetError; use sqlbuild_analysis::assembly::target_checks::main::target_error_message::target_error_message; use sqlbuild_core::text::main::python_strip::python_strip; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use sqlbuild_python_base::records::main::fields::field::field as native_field; use std::collections::HashSet; @@ -24,7 +24,7 @@ pub fn preserved_loader_schemas( if target_name.is_none() { return Ok(()); } - if !text_or_none(&native_field(&target_config, "schema")?)? + if !optional_text(&native_field(&target_config, "schema")?)? .is_some_and(|schema| python_strip(&schema) == PRESERVE_TARGET_VALUE) { return Ok(()); @@ -32,7 +32,7 @@ pub fn preserved_loader_schemas( for loader in native_field(discovered, "loader_functions")?.try_iter()? { let loader: Bound<'_, PyAny> = loader?; let name: String = native_field(&loader, "name")?.extract()?; - let destination: Option = text_or_none(&native_field(&loader, "destination")?)?; + let destination: Option = optional_text(&native_field(&loader, "destination")?)?; if !loaders.contains(&name) || destination.as_deref().is_some_and(|d| d.contains('.')) { continue; } diff --git a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs index ced7a517f7..46c90c9885 100644 --- a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs +++ b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs @@ -1,6 +1,7 @@ //! The compile-input model loop: each model's steps run in the attachment's order, natively. use crate::input_loops::models::LoopSwitches; +use sqlbuild_python_base::records::main::construct::exception_from::exception_from; use pyo3::FromPyObject; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyErr, PyResult, Python}; @@ -43,8 +44,6 @@ pub(crate) const UNMANAGED_ATTRIBUTE: &str = "unmanaged"; pub(crate) const TABLE_TYPE_ATTRIBUTE: &str = "table_type"; pub(crate) const DECLARED_ATTRIBUTE: &str = "declared"; pub(crate) const VALIDATE_METHOD: &str = "validate"; -const HELP_ARGUMENT: &str = "help"; -const CODE_ARGUMENT: &str = "code"; pub(crate) const ANALYSIS_CONFLICT: &str = "MODEL sql_analysis conflicts with legacy sql_validation"; pub(crate) const ANALYSIS_CONFLICT_CODE: &str = "P003"; @@ -269,17 +268,7 @@ pub(crate) fn record_reads( /// `CompileInputError(message, code=...)`, raised as the attachment raises it. pub(crate) fn compile_error(classes: &LoopClasses<'_>, message: &str, code: Option<&str>) -> PyErr { - let raised = (|| { - let keywords: Bound<'_, PyDict> = PyDict::new(classes.compile_error.py()); - if let Some(code) = code { - keywords.set_item(CODE_ARGUMENT, code)?; - } - classes.compile_error.call((message,), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + exception_from(Ok(classes.compile_error.clone()), message, (code, None)) } /// `CompileInputError(message, help=help)`. @@ -288,15 +277,7 @@ pub(crate) fn helped_compile_error( message: &str, help: Option<&str>, ) -> PyErr { - let raised = (|| { - let keywords: Bound<'_, PyDict> = PyDict::new(classes.compile_error.py()); - keywords.set_item(HELP_ARGUMENT, help)?; - classes.compile_error.call((message,), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + exception_from(Ok(classes.compile_error.clone()), message, (None, help)) } /// The Python exception a native config error raises as, given the values it names. diff --git a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_host.rs b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_host.rs index bd3e640752..a3ecefdb66 100644 --- a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_host.rs +++ b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_host.rs @@ -1,5 +1,6 @@ //! The Python host the loop hands finished models and user-code steps to. +use sqlbuild_python_base::boundary::main::text_item::text_item; use std::sync::Arc; use pyo3::FromPyObject; @@ -35,7 +36,6 @@ use sqlbuild_python_project::compiled_project::constants::{CONTRACT_KEY, INCREME use sqlbuild_python_project::compiled_project::main::config_values::config_values; use sqlbuild_python_project::compiled_project::main::declarations::declarations; use sqlbuild_python_project::compiled_project::main::materialization::materialization; -use sqlbuild_python_project::compiled_project::main::text_value::text_value; use sqlbuild_python_project::compiled_project::models::DeclarationPy; use sqlbuild_python_project::compiled_views::models::{ InputProjections, ModelInputHandles, SchemaHandles, @@ -310,9 +310,9 @@ pub(crate) fn finished_record<'py>( encoding_error, header_keys: native_field(&finished.config, HEADER_KEYS_ATTRIBUTE)?.extract()?, layer_schema: native_field(&finished.config, LAYER_SCHEMA_ATTRIBUTE)?.extract()?, - contract: text_value(&stripped, CONTRACT_KEY)?, + contract: text_item(&stripped, CONTRACT_KEY)?, materialized: materialization(&stripped)?, - incremental_mode: text_value(&stripped, INCREMENTAL_MODE_KEY)?, + incremental_mode: text_item(&stripped, INCREMENTAL_MODE_KEY)?, }, schema: finished.header.schema.map(|schema| schema.fact), references: finished diff --git a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs index 4d65cb532d..df8b43801b 100644 --- a/crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs +++ b/crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs @@ -1,9 +1,10 @@ //! Rejected `sql_analysis false` opt-outs, and native-route analysis skipped on a parser gap. +use crate::input_loops::_helpers::model::model_loop::helped_compile_error; use std::path::Path; use std::sync::mpsc::{Receiver, Sender, channel}; -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; +use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::types::{PyBool, PyBoolMethods, PyDict, PyDictMethods, PyList, PyString, PyTuple}; use sqlbuild_analysis::analysis_route::main::aligned_offset::aligned_offset; use sqlbuild_analysis::analysis_route::main::native_gap::native_gap; @@ -35,7 +36,7 @@ use crate::input_loops::models::NativeModelLoop; use crate::project_assembly::main::sql_entry_label::sql_entry_label; use crate::project_assembly::main::syntax_error_message::syntax_error_message; use crate::project_assembly::main::syntax_valid::syntax_valid; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -57,7 +58,6 @@ const PATH_CLASS: &str = "Path"; const PATH_FIELD: &str = "path"; const LINE_FIELD: &str = "line"; const COLUMN_FIELD: &str = "column"; -const HELP_ARGUMENT: &str = "help"; const MODEL_RESOURCE: &str = "model"; const RELATIVE_PATH_ATTRIBUTE: &str = "relative_path"; @@ -316,11 +316,11 @@ fn settle_gap( ) -> PyResult { match outcome.map_err(|message| compile_error(context.classes, &message, None))? { None => Ok(false), - Some((true, code, message)) => Err(new_helped_error( + Some((true, code, message)) => Err(new_error( context.host.py(), ErrorId::CompileInput, - (message, code), - Some(&context.classes.syntax_help), + &message, + (Some(code), Some(&context.classes.syntax_help)), )), Some((false, code, message)) => { report_skip(settings, context, model, (code, message))?; @@ -382,11 +382,11 @@ fn report_skip( let py: Python<'_> = context.host.py(); let help: &str = &context.classes.syntax_help; if settings.require_sql_analysis { - return Err(new_helped_error( + return Err(new_error( py, ErrorId::CompileInput, - (message, code), - Some(help), + &message, + (Some(code), Some(help)), )); } let diagnostic: Bound<'_, PyAny> = new_record_with( @@ -499,13 +499,10 @@ pub(crate) fn reject_unparseable_query( "SQL syntax error in model '{}' ({}): {error}", model.name, model.file_path ); - let keywords: Bound<'_, PyDict> = PyDict::new(model.config.py()); - keywords.set_item(HELP_ARGUMENT, &context.classes.syntax_help)?; - Err(PyErr::from_value( - context - .classes - .compile_error - .call((message,), Some(&keywords))?, + Err(helped_compile_error( + context.classes, + &message, + Some(&context.classes.syntax_help), )) } diff --git a/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs b/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs index 7d04d8292b..39e8d839b0 100644 --- a/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs +++ b/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs @@ -1,6 +1,7 @@ //! `build_project_audit_inputs`: singular and attached generic audits attached natively. use crate::input_loops::models::AttachmentOwner; +use sqlbuild_python_base::boundary::main::text_item::text_item; use std::collections::{BTreeMap, HashMap}; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyErr, PyResult, Python}; @@ -251,8 +252,8 @@ impl<'py> AuditScope<'_, 'py> { self.report_not_cross_resource(relative_path, &audit_name, (message, help))?; } let header: &Bound<'py, PyDict> = header.bind(py); - let severity: Option = header_text(header, SEVERITY_KEY)?; - let run_scope: Option = header_text(header, RUN_SCOPE_KEY)?; + let severity: Option = text_item(header, SEVERITY_KEY)?; + let run_scope: Option = text_item(header, RUN_SCOPE_KEY)?; let always_run: bool = match header.get_item(ALWAYS_RUN_KEY)? { Some(value) => value .downcast::() @@ -682,14 +683,6 @@ fn reference_calls(references: &[ReferenceRow]) -> Vec<(&str, &str)> { .collect() } -/// `_str_from_dict`: a header value when it is a string. -fn header_text(header: &Bound<'_, PyDict>, key: &str) -> PyResult> { - match header.get_item(key)? { - Some(value) if value.is_instance_of::() => Ok(Some(value.extract()?)), - _ => Ok(None), - } -} - /// The attachment owners of every model, source and seed, as the audit loop reads them. pub(crate) fn model_owner<'py>( py: Python<'py>, diff --git a/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs b/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs index 8678d572a6..0c222902e9 100644 --- a/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs +++ b/crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs @@ -1,5 +1,6 @@ //! Compile-input diagnostics of the project's resources, read from the native owner. +use sqlbuild_python_base::boundary::main::text_item::text_item; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::sync::Arc; @@ -506,13 +507,6 @@ fn function_description<'py>( ) } -fn config_text(values: &Bound<'_, PyDict>, key: &str) -> PyResult> { - match values.get_item(key)? { - Some(value) if value.is_instance_of::() => Ok(Some(value.extract()?)), - _ => Ok(None), - } -} - fn cursor_without_inputs<'py>( project: &NativeCompiledProject, diagnostics: &Diagnostics<'_, 'py>, @@ -527,9 +521,9 @@ fn cursor_without_inputs<'py>( .iter() .map(|ReferenceRow { kind, .. }| kind.as_str()) .collect(); - let materialized: Option = config_text(&values, "materialized")?; - let cursor: Option = config_text(&values, CURSOR_KEY)?; - let strategy: Option = config_text(&values, "microbatch_strategy")?; + let materialized: Option = text_item(&values, "materialized")?; + let cursor: Option = text_item(&values, CURSOR_KEY)?; + let strategy: Option = text_item(&values, "microbatch_strategy")?; let model_file: &NativeModelFile = record.host.model_file.get(); let name: String = record.name.clone(); let Some((message, help)) = cursor_lacks_inputs( diff --git a/crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs b/crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs index 3b1cd25a9d..36934e7e4e 100644 --- a/crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs +++ b/crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs @@ -2,15 +2,15 @@ use crate::project_assembly::main::sql_entry_label::sql_entry_label; use crate::project_assembly::main::syntax_error_message::syntax_error_message; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::HashMap; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::pyfunction; -use pyo3::types::{PyDict, PyList, PyString, PyTuple}; +use pyo3::types::{PyList, PyString, PyTuple}; use sqlbuild_analysis::assembly::project::main::sql_analysis_opt_out_help::sql_analysis_opt_out_help; use sqlbuild_analysis::assembly::project::models::{SyntaxCheck, SyntaxMode}; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -37,14 +37,12 @@ pub(crate) struct HookSite<'a, 'py> { /// `CompileInputError(message, help=sql_analysis_opt_out_help(model_owned=True))`. pub(crate) fn syntax_error(py: Python<'_>, message: String) -> PyErr { - let raised = || -> PyResult { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("help", sql_analysis_opt_out_help(true))?; - let error: Bound<'_, PyAny> = - error_class(py, ErrorId::CompileInput)?.call((message,), Some(&keywords))?; - Ok(PyErr::from_value(error)) - }; - raised().unwrap_or_else(|error| error) + new_error( + py, + ErrorId::CompileInput, + &message, + (None, Some(&sql_analysis_opt_out_help(true))), + ) } /// The parser's message for `sql`, or `None` where it parses. diff --git a/crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs b/crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs index be07a6d854..9f4b846100 100644 --- a/crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs +++ b/crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs @@ -1,8 +1,8 @@ //! DSL header values parsed natively for header rules, compared as Python compares their objects. use crate::rules::models::NativeHeaderParser; -use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods}; +use pyo3::prelude::{PyErr, Python}; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_rules::dsl_headers::main::inner_header_text::inner_header_text; use sqlbuild_rules::dsl_headers::models::{HeaderSpan, ParseFailure, ParseOutcome}; use sqlbuild_rules::dsl_headers::types::HeaderParser; @@ -10,7 +10,6 @@ use sqlbuild_sqltext::compiler::main::header_word_value::header_word_value; use sqlbuild_sqltext::compiler::models::{AuthoredValue, HeaderWord}; use sqlbuild_python_base::boundary::main::value_error::value_error; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; /// The path header rules report header syntax errors at. @@ -23,14 +22,12 @@ const ZERO: &str = "0"; /// The `ModelSqlParseError` a rejected header parse raises. pub(crate) fn rejection(py: Python<'_>, failure: ParseFailure) -> PyErr { - let raised: PyResult = (|| { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("help", failure.help)?; - let error: Bound<'_, PyAny> = - error_class(py, ErrorId::ModelSqlParse)?.call((failure.message,), Some(&keywords))?; - Ok(PyErr::from_value(error)) - })(); - raised.unwrap_or_else(|error| error) + new_error( + py, + ErrorId::ModelSqlParse, + &failure.message, + (None, failure.help.as_deref()), + ) } /// Why a header could not be read: a header syntax error, or a native failure's message. diff --git a/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs b/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs index 24d8b4bfd4..19a5cafb28 100644 --- a/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs +++ b/crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs @@ -3,8 +3,9 @@ use crate::compile_driver::main::session_warehouse_support::session_warehouse_support; use crate::compile_driver::models::ProjectConfiguration; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::types::{PyBool, PyDict, PyString, PyTuple}; +use pyo3::types::{PyBool, PyString, PyTuple}; use sqlbuild_config::project::main::unsupported_target_warehouse::unsupported_target_warehouse; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use crate::contracts::main::resolve_effective_adapter_name::resolve_effective_adapter_name; use crate::contracts::main::resolve_target_config::resolve_target_config; @@ -21,15 +22,7 @@ const SQL_ANALYSIS_KEY: &str = "sql_analysis"; const WAREHOUSE_GROUPS: [&str; 2] = ["build", "query"]; fn project_config_error(py: Python<'_>, message: &str, help: Option<&str>) -> PyErr { - let raised = (|| -> PyResult> { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("help", help)?; - error_class(py, ErrorId::ProjectConfig)?.call((message,), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + new_error(py, ErrorId::ProjectConfig, message, (None, help)) } /// The target names of one configuration's `targets` mapping. diff --git a/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs index 69cd824d73..635ac44139 100644 --- a/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/expansion/macro_expansion.rs @@ -19,7 +19,7 @@ use crate::render::_helpers::expansion::macro_evaluation::{CallText, Evaluation, use crate::render::_helpers::expansion::macro_expansion_facts::ResourceRef; use crate::render::_helpers::expansion::macro_generated_references::GeneratedReferenceClasses; use crate::render::models::SpanTuple; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -233,11 +233,11 @@ pub(crate) fn sorted_names(names: &Bound<'_, PyAny>) -> PyResult { /// The `CompileInputError(message, code=code, help=help)` the classes' compile error builds. pub(crate) fn coded(class: &Bound<'_, PyAny>, message: &str, (code, help): (&str, &str)) -> PyErr { - new_helped_error( + new_error( class.py(), ErrorId::CompileInput, - (message.to_owned(), code), - Some(help), + message, + (Some(code), Some(help)), ) } diff --git a/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs index ef2be07911..5cc5adb91f 100644 --- a/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_host.rs @@ -34,7 +34,7 @@ use crate::render::_helpers::declarations::declaration_expansion::{ use crate::render::models::{DeclarationExpansion, ExpandedDeclarations}; use crate::sqltext::main::declaration_scan::declaration_scan; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -256,11 +256,11 @@ fn macro_error(request: &DeclarationExpansion<'_, '_>, error: &SqlMacroError) -> Ok(model) => model, Err(failure) => return failure, }; - new_helped_error( + new_error( request.classes.compile_error.py(), ErrorId::CompileInput, - (error.located_message(model.as_deref()), error.code), - error.help.as_deref(), + &error.located_message(model.as_deref()), + (Some(error.code), error.help.as_deref()), ) } diff --git a/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs index 3f9f194765..7325c26c5e 100644 --- a/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs +++ b/crates/sqlbuild-python-front/src/render/_helpers/sql_macros/sql_macro_inventory.rs @@ -8,7 +8,7 @@ use sqlbuild_analysis::sql_macros::main::parse_sql_macro::parse_sql_macro; use sqlbuild_analysis::sql_macros::main::sql_macro_cycle::sql_macro_cycle; use sqlbuild_analysis::sql_macros::models::{SqlMacroDefinition, SqlMacroLocation}; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::types::ErrorId; /// `(name, relative path, contents)` of one SQL macro file. @@ -17,11 +17,11 @@ type SourceRow = (String, String, String); type DefinitionRow = (String, Vec, Vec); fn raised(py: Python<'_>, error: &SqlMacroError) -> PyErr { - new_helped_error( + new_error( py, ErrorId::CompileInput, - (error.located_message(None), error.code), - error.help.as_deref(), + &error.located_message(None), + (Some(error.code), error.help.as_deref()), ) } diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs index 17f991f70a..5c54fdf930 100644 --- a/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs @@ -3,6 +3,7 @@ use crate::state_rows::main::event_rows::in_utc::in_utc; use crate::state_rows::main::event_rows::offset_aware::offset_aware; use crate::state_rows::main::event_rows::presumed_utc::presumed_utc; +use sqlbuild_python_base::records::main::construct::exception_from::exception_from; use std::cell::RefCell; use pyo3::exceptions::PyOverflowError; @@ -58,10 +59,7 @@ pub(crate) fn record_event_id(record: &Bound<'_, PyAny>) -> PyResult { } pub(crate) fn raised(py: Python<'_>, class: NativeAttr, message: String) -> PyErr { - match native_attr(py, class).and_then(|class| class.call1((message,))) { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + exception_from(native_attr(py, class), &message, (None, None)) } pub(crate) fn python_error(py: Python<'_>, error: FreshnessError) -> PyErr { diff --git a/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs index 31f669810e..933e2e3b3d 100644 --- a/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs +++ b/crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs @@ -6,6 +6,7 @@ use pyo3::pyfunction; use pyo3::types::{PyDict, PyString, PyStringMethods}; use sqlbuild_core::constants::SOURCE_FRESHNESS_TABLE_NAME; use sqlbuild_host::entries::models::AdapterHost; +use sqlbuild_python_base::records::main::construct::exception_from::exception_from; use sqlbuild_state::freshness::constants::{ SOURCE_FRESHNESS_COLUMN_TYPES, SOURCE_FRESHNESS_EVENT_ID, STRING_STATE_VALUE_TYPE, TEXT_TIMESTAMP_STATE_VALUE_TYPE, @@ -83,15 +84,11 @@ pub(crate) fn render_create_sql(request: Option<&Bound<'_, PyDict>>) -> PyResult } fn adapter_user_error(py: Python<'_>, message: &str) -> PyErr { - match host_entry(py, AdapterHost::AdapterUserError).and_then(|class| { - call_with( - &class, - &[("message", PyString::new(py, message).into_any())], - ) - }) { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + exception_from( + host_entry(py, AdapterHost::AdapterUserError), + message, + (None, None), + ) } /// Render DML that appends source freshness records. diff --git a/crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs b/crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs index a7a4410d8c..31720fe93d 100644 --- a/crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs +++ b/crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs @@ -3,9 +3,7 @@ use pyo3::exceptions::PyTypeError; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::pyfunction; -use pyo3::types::{ - PyBool, PyByteArray, PyBytes, PyDict, PyDictMethods, PyInt, PyString, PyTypeMethods, -}; +use pyo3::types::{PyBool, PyByteArray, PyBytes, PyDict, PyDictMethods, PyInt, PyTypeMethods}; use sqlbuild_core::lifecycle_events::constants::INVOCATION_SEQUENCE_PROBLEM; use sqlbuild_core::lifecycle_events::main::diagnostic_severity_problem::diagnostic_severity_problem; use sqlbuild_core::lifecycle_events::main::diagnostic_version_problem::diagnostic_version_problem; @@ -16,6 +14,7 @@ use sqlbuild_core::lifecycle_events::main::producer_version_problem::producer_ve use sqlbuild_core::lifecycle_events::main::publishable_hook_name::publishable_hook_name; use sqlbuild_core::lifecycle_events::main::run_bounds_problem::run_bounds_problem; use sqlbuild_core::lifecycle_events::models::{HookFacts, SequenceFact}; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use crate::lifecycle_events::_helpers::payloads::validation_error; use crate::lifecycle_events::_helpers::validation::{ @@ -77,14 +76,6 @@ fn saturated(value: &Bound<'_, PyAny>) -> PyResult { } } -/// The text a value holds when it is a string. -fn text(value: &Bound<'_, PyAny>) -> PyResult> { - match value.downcast::() { - Ok(text) => Ok(Some(text.extract()?)), - Err(_) => Ok(None), - } -} - /// Freeze a JSON object field of a frozen dataclass in place. fn freeze_object_field(owner: &Bound<'_, PyAny>, field: &str, path: &str) -> PyResult<()> { let py: Python<'_> = owner.py(); @@ -212,7 +203,7 @@ pub(crate) fn validated_operation_metadata<'py>( return Ok(result); } for key in metadata.try_iter()? { - if !operation_metadata_field(text(&key?)?.as_deref()) { + if !operation_metadata_field(optional_text(&key?)?.as_deref()) { return Err(validation_error( py, "operation metadata contains a non-allowlisted field", @@ -234,7 +225,7 @@ pub(crate) fn validated_operation_metadata<'py>( /// Whether a hook name is publishable, raising like `re.fullmatch` for non-string names. fn hook_name_publishable(name: &Bound<'_, PyAny>) -> PyResult { - if let Some(name) = text(name)? { + if let Some(name) = optional_text(name)? { return Ok(publishable_hook_name(&name)); } if name.is_instance_of::() || name.is_instance_of::() { @@ -265,8 +256,8 @@ pub(crate) fn validated_operation_hook_fields<'py>( if !supplied { return Ok(result); } - let phase: Option = text(hook_phase)?; - let hook_type_text: Option = text(hook_type)?; + let phase: Option = optional_text(hook_phase)?; + let hook_type_text: Option = optional_text(hook_type)?; let facts = HookFacts { phase: phase.as_deref(), hook_type: hook_type_text.as_deref(), @@ -291,7 +282,10 @@ pub(crate) fn producer_check( producer: &Bound<'_, PyAny>, producer_version: &Bound<'_, PyAny>, ) -> PyResult<()> { - match producer_version_problem(text(producer)?.as_deref(), !producer_version.is_none()) { + match producer_version_problem( + optional_text(producer)?.as_deref(), + !producer_version.is_none(), + ) { Some(problem) => Err(validation_error(producer.py(), problem)), None => Ok(()), } diff --git a/crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs b/crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs index 61ca98707b..8a77555b40 100644 --- a/crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs +++ b/crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs @@ -1,7 +1,8 @@ //! The source texts a changed Python node's identity diffs compare. use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyModule, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods, PyString}; +use pyo3::types::{PyDict, PyDictMethods, PyList, PyListMethods}; +use sqlbuild_python_base::boundary::main::text_item::text_item; use sqlbuild_python_base::records::main::fields::field::field as native_field; const DEPENDENCY_HEADER_SEPARATOR: &str = " :: "; @@ -28,18 +29,10 @@ fn json_object<'py>(raw_json: &Bound<'py, PyAny>) -> PyResult, key: &str) -> PyResult> { - match payload.get_item(key)? { - Some(value) if value.is_instance_of::() => Ok(Some(value.extract()?)), - _ => Ok(None), - } -} - /// The recorded definition's `source_text`. pub(crate) fn definition_source_text(raw_json: &Bound<'_, PyAny>) -> PyResult> { match json_object(raw_json)? { - Some(payload) => string_field(&payload, "source_text"), + Some(payload) => text_item(&payload, "source_text"), None => Ok(None), } } @@ -63,7 +56,7 @@ pub(crate) fn dependency_source_text(raw_json: &Bound<'_, PyAny>) -> PyResult) -> PyResult = key diff --git a/crates/sqlbuild-python-project/src/compiled_project/main/materialization.rs b/crates/sqlbuild-python-project/src/compiled_project/main/materialization.rs index ca4573eee6..86cff0ba39 100644 --- a/crates/sqlbuild-python-project/src/compiled_project/main/materialization.rs +++ b/crates/sqlbuild-python-project/src/compiled_project/main/materialization.rs @@ -2,14 +2,14 @@ use crate::compiled_project::_helpers::project::MATERIALIZED_KEY; use crate::compiled_project::_helpers::project::TABLE_MATERIALIZATION; -use crate::compiled_project::main::text_value::text_value; use pyo3::prelude::{Bound, PyResult}; use pyo3::types::{PyDict, PyDictMethods}; +use sqlbuild_python_base::boundary::main::text_item::text_item; /// The `materialized` config value when it is text, `table` when it is absent. pub fn materialization(values: &Bound<'_, PyDict>) -> PyResult> { if values.get_item(MATERIALIZED_KEY)?.is_none() { return Ok(Some(TABLE_MATERIALIZATION.to_owned())); } - text_value(values, MATERIALIZED_KEY) + text_item(values, MATERIALIZED_KEY) } diff --git a/crates/sqlbuild-python-project/src/compiled_project/main/mod.rs b/crates/sqlbuild-python-project/src/compiled_project/main/mod.rs index 1a34adb72d..cbc2c7c0c7 100644 --- a/crates/sqlbuild-python-project/src/compiled_project/main/mod.rs +++ b/crates/sqlbuild-python-project/src/compiled_project/main/mod.rs @@ -13,6 +13,5 @@ pub mod python_column_fact; pub mod python_column_facts; pub mod reference_row_tuple; pub mod register_project; -pub mod text_value; pub mod triggered_jobs; pub mod with_job_scope; diff --git a/crates/sqlbuild-python-project/src/compiled_project/main/model_facts.rs b/crates/sqlbuild-python-project/src/compiled_project/main/model_facts.rs index ce21e47ad3..06de05dc2d 100644 --- a/crates/sqlbuild-python-project/src/compiled_project/main/model_facts.rs +++ b/crates/sqlbuild-python-project/src/compiled_project/main/model_facts.rs @@ -7,12 +7,12 @@ use crate::compiled_project::constants::INCREMENTAL_MODE_KEY; use crate::compiled_project::main::config_values::config_values; use crate::compiled_project::main::declarations::declarations; use crate::compiled_project::main::materialization::materialization; -use crate::compiled_project::main::text_value::text_value; use crate::compiled_project::models::ModelInputPy; use pyo3::prelude::PyResult; use sqlbuild_analysis::compiled_project::models::{ CompiledModelFacts, ModelConfigFacts, ModelReferenceFact, }; +use sqlbuild_python_base::boundary::main::text_item::text_item; /// Model facts. pub fn model_facts(model: ModelInputPy<'_>) -> PyResult { @@ -41,9 +41,9 @@ pub fn model_facts(model: ModelInputPy<'_>) -> PyResult { encoding_error: config_values.1, header_keys, layer_schema, - contract: text_value(&values, CONTRACT_KEY)?, + contract: text_item(&values, CONTRACT_KEY)?, materialized: materialization(&values)?, - incremental_mode: text_value(&values, INCREMENTAL_MODE_KEY)?, + incremental_mode: text_item(&values, INCREMENTAL_MODE_KEY)?, }, references: references .into_iter() diff --git a/crates/sqlbuild-python-project/src/compiled_project/main/text_value.rs b/crates/sqlbuild-python-project/src/compiled_project/main/text_value.rs deleted file mode 100644 index 6003013b76..0000000000 --- a/crates/sqlbuild-python-project/src/compiled_project/main/text_value.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! A config value when it is text. - -use pyo3::prelude::{Bound, PyAnyMethods, PyResult}; -use pyo3::types::{PyDict, PyDictMethods, PyString}; - -/// A config value when it is text. -pub fn text_value(values: &Bound<'_, PyDict>, key: &str) -> PyResult> { - match values.get_item(key)? { - Some(value) if value.is_instance_of::() => Ok(Some(value.extract()?)), - _ => Ok(None), - } -} diff --git a/crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs b/crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs index dca81a3464..119d67c162 100644 --- a/crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs +++ b/crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs @@ -5,13 +5,14 @@ use crate::compiled_views::types::LineageInput; use sqlbuild_project::models as project_models; use sqlbuild_project::models::DestinationFact; use sqlbuild_project::types::InferredRow; +use sqlbuild_python_base::boundary::main::text_item::text_item; use sqlbuild_python_front::model_config::models::HeaderAudits; use std::sync::Arc; use pyo3::FromPyObject; use pyo3::prelude::{Bound, Py, PyAny, PyAnyMethods, PyResult, Python}; use pyo3::sync::PyOnceLock; -use pyo3::types::{PyDict, PyDictMethods, PyTuple}; +use pyo3::types::{PyDict, PyTuple}; use sqlbuild_analysis::assembly::analysis_session::models::LineageRow; @@ -113,9 +114,9 @@ pub(crate) fn compiled_record( Ok(CompiledRecord { deps, destination: DestinationFact { - database: text_value(&values, DATABASE_KEY)?, - schema: text_value(&values, SCHEMA_KEY)?, - name: text_value(&values, ALIAS_KEY)?.unwrap_or_else(|| name.to_owned()), + database: text_item(&values, DATABASE_KEY)?, + schema: text_item(&values, SCHEMA_KEY)?, + name: text_item(&values, ALIAS_KEY)?.unwrap_or_else(|| name.to_owned()), qualified_name: None, logical_schema: native_field(config, LOGICAL_SCHEMA_ATTRIBUTE)?.extract()?, logical_database: native_field(config, LOGICAL_DATABASE_ATTRIBUTE)?.extract()?, @@ -126,15 +127,6 @@ pub(crate) fn compiled_record( }) } -fn text_value(values: &Bound<'_, PyDict>, key: &str) -> PyResult> { - match values.get_item(key)? { - Some(value) if value.is_instance_of::() => { - Ok(Some(value.extract()?)) - } - _ => Ok(None), - } -} - /// A lineage row's output column with its `(resource name, column)` sources. pub(crate) fn lineage_input(row: &LineageRow) -> LineageInput { let mut sources: Vec<(String, String)> = Vec::with_capacity(row.sources.len()); diff --git a/crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs b/crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs index 6d7c157329..1cd6175c21 100644 --- a/crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs +++ b/crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs @@ -2,11 +2,12 @@ use crate::graph::main::python_nodes::python_node_names::python_node_names; use sqlbuild_python_base::positional_record; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::borrow::Cow; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; use pyo3::pyfunction; -use pyo3::types::{PyDict, PyFrozenSet}; +use pyo3::types::PyFrozenSet; use sqlbuild_analysis::assembly::project::types::ObjectKey; use sqlbuild_analysis::graph::errors::SelectorError; use sqlbuild_analysis::graph::models::ProjectGraph; @@ -21,7 +22,6 @@ use sqlbuild_analysis::python_selection::models::{ use crate::compiled_project::main::needed_jobs::needed_jobs; use crate::graph::models::{CompiledProjectGraph, NativeProjectGraph}; use sqlbuild_python_base::boundary::main::compiler_guard::compiler_guard; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; use sqlbuild_python_base::records::types::ErrorId; @@ -52,16 +52,12 @@ positional_record! { /// The `PlannerInputError` Python raises for a selector failure. pub(crate) fn planner_error(py: Python<'_>, error: SelectorError) -> PyErr { - let raised = (|| -> PyResult> { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", error.code)?; - keywords.set_item("help", error.help)?; - error_class(py, ErrorId::PlannerInput)?.call((error.message,), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + new_error( + py, + ErrorId::PlannerInput, + &error.message, + (Some(error.code), error.help.as_deref()), + ) } fn strings(values: &Bound<'_, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python-project/src/references/_helpers/source_relations.rs b/crates/sqlbuild-python-project/src/references/_helpers/source_relations.rs index 0e2fe20777..f5806a335c 100644 --- a/crates/sqlbuild-python-project/src/references/_helpers/source_relations.rs +++ b/crates/sqlbuild-python-project/src/references/_helpers/source_relations.rs @@ -1,10 +1,9 @@ //! A declared source rendered as the SQL table factor that reads it. use sqlbuild_host::entries::models::AdapterHost; +use sqlbuild_python_base::records::main::construct::exception_from::exception_from; use pyo3::prelude::{PyErr, Python}; -use pyo3::types::PyString; -use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; /// The SQL analysis dialect whose engines read replacing tables with `FINAL`. @@ -37,26 +36,9 @@ pub(crate) fn expression_relation(expression: &str) -> String { /// The coded error for a `final` source on an adapter that cannot read with `FINAL`. pub(crate) fn final_unsupported(py: Python<'_>, adapter_name: &str) -> PyErr { - match host_entry(py, AdapterHost::AdapterUserError).and_then(|class| { - call_with( - &class, - &[ - ( - "message", - PyString::new( - py, - &format!( - "adapter '{adapter_name}' does not support the source option 'final'" - ), - ) - .into_any(), - ), - ("code", PyString::new(py, FINAL_UNSUPPORTED_CODE).into_any()), - ("help", PyString::new(py, FINAL_UNSUPPORTED_HELP).into_any()), - ], - ) - }) { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + exception_from( + host_entry(py, AdapterHost::AdapterUserError), + &format!("adapter '{adapter_name}' does not support the source option 'final'"), + (Some(FINAL_UNSUPPORTED_CODE), Some(FINAL_UNSUPPORTED_HELP)), + ) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs b/crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs index e4498db77e..c73dffaed4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs @@ -15,9 +15,9 @@ use sqlbuild_core::build_command::models::{ PlanWarningFact, PolicyStep, RetentionFact, SnapshotPolicies, SnapshotRefreshFact, TableTypeFact, }; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::boundary::models::KeywordArguments; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -43,16 +43,12 @@ const LIMIT_OPTIONS: (&[&str], &[&str]) = ( /// `CliUserError(message, code=..., help=...)`. pub(crate) fn build_command_error(py: Python<'_>, error: BuildCommandError) -> PyErr { - let raised: PyResult> = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", error.code)?; - options.set_item("help", error.help)?; - error_class(py, ErrorId::CliUser)?.call((error.message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &error.message, + (error.code.as_deref(), error.help.as_deref()), + ) } fn text(value: &Bound<'_, PyAny>, name: &str) -> PyResult { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs index 72fea2661e..c6ae2e6091 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs @@ -1,6 +1,7 @@ //! `sqb check`: run the selected Python checks after their Python dependencies. use sqlbuild_host::entries::models::{ExecutorHost, UserCodeHost}; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use crate::bindings::_helpers::build_progress::progress_text::write_execution_header; use crate::bindings::_helpers::compile_driver::static_context::compile_static_command_context; @@ -50,7 +51,6 @@ use crate::bindings::_helpers::command_runtime::invocation::resolve_reported_com use crate::bindings::_helpers::result_output::event_writer::ExecutionEventWriter; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::native_host::main::host_entry::host_entry; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; @@ -77,15 +77,7 @@ struct Prepared<'py> { } fn user_error(py: Python<'_>, (code, message): (&str, &str)) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, message, (Some(code), None)) } fn selection_error(py: Python<'_>, error: &CheckSelectionError) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs b/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs index 67b92cc3d9..4a5a528cbf 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs @@ -1,5 +1,6 @@ //! `sqb` command dispatch: the native route table applied to a parsed namespace. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::path::PathBuf; use crate::bindings::_helpers::audit_command::command::run_audit_command; @@ -60,7 +61,6 @@ use sqlbuild_python_project::compiled_project::main::with_job_scope::with_job_sc use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::registry::record_named::record_named; use sqlbuild_python_base::records::types::ErrorId; @@ -266,16 +266,12 @@ fn concatenated<'py>( /// `CliUserError(message, code=..., help=...)`. fn user_error(py: Python<'_>, failure: DispatchFailure) -> PyErr { - let raised = (|| { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", failure.code)?; - keywords.set_item("help", failure.help)?; - error_class(py, ErrorId::CliUser)?.call((failure.message,), Some(&keywords)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &failure.message, + (Some(failure.code), failure.help), + ) } /// `--select` and the selectors of every `--select-file`, with each file's selector count. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cli/entry.rs b/crates/sqlbuild-python/src/bindings/_helpers/cli/entry.rs index 6921f7d3d7..ff3a8155a4 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cli/entry.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cli/entry.rs @@ -748,8 +748,8 @@ fn report_dispatch<'py>(invocation: &Invocation<'py>) -> PyResult Err(new_error( py, ErrorId::CliUser, - message.clone(), - RECALL_SETTINGS_CODE, + message, + (Some(RECALL_SETTINGS_CODE), None), )), None => observed_dispatch(invocation, policy), }; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs index 461b7fb13a..e7861f767e 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs @@ -1,5 +1,6 @@ //! `sqb clone`: copy or clone selected relations from an origin target into a destination target. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::BTreeSet; use std::time::Instant; @@ -37,7 +38,6 @@ use sqlbuild_python_base::command_runtime::main::resolve_cli_adapter::resolve_cl use sqlbuild_python_base::native_host::main::connection_failure::connection_failure; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -72,15 +72,7 @@ pub(crate) struct Invocation<'py> { } fn user_error(py: Python<'_>, (code, message): (&str, &str)) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, message, (Some(code), None)) } fn target_error(py: Python<'_>, error: CloneTargetError) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs index 010058a310..bf3309c986 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs @@ -1,5 +1,6 @@ //! `sqb contract`: compare selected contracts with one target, optionally adopt them. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::time::Instant; use pyo3::exceptions::{PyException, PyValueError}; @@ -30,7 +31,6 @@ use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::build_progress::main::transient_status::status_reporter::status_reporter; use sqlbuild_python_base::native_host::main::connection_failure::connection_failure; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -43,15 +43,7 @@ const GENERATE_ACTION: &str = "generate"; /// A `CliUserError` with its code. fn user_error(py: Python<'_>, message: &str, code: &str) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, message, (Some(code), None)) } fn optional_text(value: Bound<'_, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs b/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs index 5f62f68d6f..adb0c053c8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs @@ -1,21 +1,17 @@ //! Cost command errors raised as `CliUserError`. -use pyo3::prelude::{Bound, PyAnyMethods, PyErr, Python}; -use pyo3::types::{PyDict, PyDictMethods}; +use pyo3::prelude::{PyErr, Python}; use sqlbuild_core::cost_command::errors::CostCommandError; +use sqlbuild_python_base::records::main::construct::new_error::new_error; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::types::ErrorId; /// The `CliUserError` for a refused cost request. pub(crate) fn cost_error(py: Python<'_>, error: &CostCommandError) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", error.code)?; - error_class(py, ErrorId::CliUser)?.call((error.message.as_str(),), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(failure) => failure, - } + new_error( + py, + ErrorId::CliUser, + &error.message, + (Some(error.code), None), + ) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs index b5655b1f75..5f3ece3259 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs @@ -3,38 +3,31 @@ use pyo3::prelude::{ Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; -use pyo3::types::{PyDict, PyDictMethods}; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::cli_text::models::CliStyle; use sqlbuild_core::dbt_command::constants::DBT_PROJECT_FILE; use sqlbuild_core::dbt_command::main::render_dbt_init_preview::render_dbt_init_preview; use sqlbuild_core::dbt_command::main::render_dbt_init_summary::render_dbt_init_summary; use sqlbuild_core::dbt_command::models::DbtInitSummary; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use crate::bindings::_helpers::build_progress::progress_reporters::DbtInitProgressReporter; use crate::bindings::_helpers::dbt_command::init_project::build_dbt_init_project; use crate::bindings::_helpers::dbt_command::init_project::validate_dbt_init_project; use crate::bindings::_helpers::dbt_command::support::{color_enabled, flag, path, stream}; use sqlbuild_python_base::boundary::main::imported::imported; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_base::records::types::RecordId; fn missing_project(py: Python<'_>) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", "C242")?; - error_class(py, ErrorId::CliUser)?.call( - ("sqb dbt init requires --project-dir pointing at a dbt project",), - Some(&options), - ) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + "sqb dbt init requires --project-dir pointing at a dbt project", + (Some("C242"), None), + ) } /// `Path(value)`, or `None` when the option was not given. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init_project.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init_project.rs index 5a6f00f6a0..11d70fdfe2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init_project.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init_project.rs @@ -1,6 +1,6 @@ //! Build or validate a SQLBuild project from a dbt project, its profile and `dbt debug`. -use sqlbuild_python_base::native_host::main::host_error::host_error; +use crate::bindings::_helpers::dbt_interop::profile_connection::profile_error; use std::io; use pyo3::exceptions::PyRuntimeError; @@ -349,10 +349,6 @@ fn is_value_error(py: Python<'_>, error: &PyErr) -> bool { error.is_instance_of::(py) } -fn profile_error(py: Python<'_>, message: String) -> PyErr { - host_error(py, ThirdPartyHost::DbtProfileError, &message) -} - pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> { module.add_function(wrap_pyfunction!(build_dbt_init_project, module)?)?; module.add_function(wrap_pyfunction!(validate_dbt_init_project, module)?) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs index 14e8247302..210ef7ef7c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs @@ -3,7 +3,7 @@ use pyo3::prelude::{ Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; -use pyo3::types::{PyDict, PyDictMethods, PyString, PyTuple}; +use pyo3::types::{PyDict, PyString, PyTuple}; use pyo3::{pyfunction, wrap_pyfunction}; use serde_json::{Map, Value}; use sqlbuild_core::dbt_cli::errors::DbtCliError; @@ -17,12 +17,12 @@ use sqlbuild_core::dbt_cli::models::{ }; use sqlbuild_core::text::main::python_splitlines::python_splitlines; use sqlbuild_core::text::main::python_strip::python_strip; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::records::main::construct::enum_from_value::enum_from_value; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -249,19 +249,7 @@ pub(crate) fn ls_nodes<'py>(py: Python<'py>, stdout: &str) -> PyResult, class_name: ErrorId, error: DbtCliError) -> PyErr { - let created = || -> PyResult { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - if let Some(code) = error.code { - keywords.set_item("code", code)?; - } - if let Some(help) = error.help { - keywords.set_item("help", help)?; - } - let instance: Bound<'_, PyAny> = - error_class(py, class_name)?.call((error.message,), Some(&keywords))?; - Ok(PyErr::from_value(instance)) - }; - created().unwrap_or_else(|failure| failure) + new_error(py, class_name, &error.message, (error.code, error.help)) } fn parsed_flags(parsed: &Bound<'_, PyAny>) -> PyResult { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs index 956e86a5b7..dcaa409e64 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs @@ -1,5 +1,6 @@ //! The combined dbt and SQLBuild graph, `sqb dbt` selector resolution and dbt selector terms. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::{HashMap, HashSet}; use pyo3::prelude::{ @@ -21,7 +22,6 @@ use sqlbuild_core::dbt_graph::types::DbtSelectorResolver; use crate::bindings::_helpers::dbt_interop::manifest::resolve_sqlbuild_model_dbt_refs; use sqlbuild_python_base::boundary::models::KeywordArguments; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::mapping_items::mapping_items; @@ -210,16 +210,12 @@ impl DbtSelectorResolver for PlannerResolver<'_> { fn selection_error(py: Python<'_>, error: DbtSelectionError) -> PyErr { match error { DbtSelectionError::Resolver(error) => error, - DbtSelectionError::PathSelector(message) => { - let raised = || -> PyResult { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", PATH_SELECTOR_ERROR_CODE)?; - let error: Bound<'_, PyAny> = error_class(py, ErrorId::DbtInteropArgument)? - .call((message,), Some(&keywords))?; - Ok(PyErr::from_value(error)) - }; - raised().unwrap_or_else(|failure| failure) - } + DbtSelectionError::PathSelector(message) => new_error( + py, + ErrorId::DbtInteropArgument, + &message, + (Some(PATH_SELECTOR_ERROR_CODE), None), + ), } } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs index eeacdf045a..ebd2e92eef 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs @@ -1,5 +1,6 @@ //! dbt manifest loading, indexing and `__dbt_ref` resolution. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::HashSet; use pyo3::prelude::{ @@ -21,7 +22,6 @@ use sqlbuild_config::dbt_manifest::models::{ use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::models::KeywordArguments; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -32,15 +32,12 @@ const RELATION_OPTIONS: (&[&str], &[&str]) = (&["manifest", "ref_kind", "ref_name", "ref_package"], &[]); fn raised(py: Python<'_>, error: ManifestError) -> PyErr { - let created = || -> PyResult { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", error.code)?; - keywords.set_item("help", error.help)?; - let instance: Bound<'_, PyAny> = - error_class(py, ErrorId::CompileInput)?.call((error.message,), Some(&keywords))?; - Ok(PyErr::from_value(instance)) - }; - created().unwrap_or_else(|failure| failure) + new_error( + py, + ErrorId::CompileInput, + &error.message, + (Some(error.code), error.help.as_deref()), + ) } fn text_value(value: Option>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs index 4eb43809e4..0fb59069eb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs @@ -6,6 +6,7 @@ use pyo3::types::{PyDict, PyDictMethods}; use sqlbuild_cli::diff_report::errors::DiffUserError; use sqlbuild_cli::diff_report::models::DiffRequestFacts; use sqlbuild_host::entries::models::HostId; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::native_host::main::host_entry::host_entry; @@ -38,17 +39,12 @@ pub(crate) fn object<'py, T: pyo3::IntoPyObjectExt<'py>>( /// `class(message, code=code, help=help)` from the CLI exceptions module. pub(crate) fn cli_error(py: Python<'_>, class: ErrorId, error: &DiffUserError) -> PyErr { - let raised = (|| -> PyResult> { - let help: Bound<'_, PyAny> = object(py, error.help.as_deref())?; - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", error.code.as_str())?; - keywords.set_item("help", help)?; - error_class(py, class)?.call((error.message.as_str(),), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + new_error( + py, + class, + &error.message, + (Some(&error.code), error.help.as_deref()), + ) } /// The `message`, `code` and `help` of a raised `CliUserError`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs index 0585f065b3..b86223f567 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs @@ -3,8 +3,9 @@ use pyo3::IntoPyObjectExt; use pyo3::exceptions::PyValueError; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::types::{PyBool, PyInt, PyList, PyString, PyStringMethods, PyTuple}; +use pyo3::types::{PyBool, PyInt, PyList, PyTuple}; use sqlbuild_host::entries::models::ExecutorHost; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use sqlbuild_python_base::native_host::main::host_error::host_error; use sqlbuild_state::execution_history::constants::ENVELOPE_TEXT_FIELDS; use sqlbuild_state::execution_history::errors::{HistoryError, HistoryErrorKind}; @@ -78,16 +79,8 @@ pub(crate) fn exact_int(value: &Bound<'_, PyAny>) -> Option { value.extract().unwrap_or(None) } -/// `value` as text when it is a `str`. -pub(crate) fn text_of(value: &Bound<'_, PyAny>) -> PyResult> { - match value.downcast::() { - Ok(text) => Ok(Some(text.to_str()?.to_owned())), - Err(_) => Ok(None), - } -} - /// `value` as text, or `None` when it is `None`. -pub(crate) fn optional_text(value: &Bound<'_, PyAny>) -> PyResult> { +pub(crate) fn nullable_text(value: &Bound<'_, PyAny>) -> PyResult> { if value.is_none() { return Ok(None); } @@ -160,9 +153,9 @@ fn texts(value: &Bound<'_, PyAny>) -> PyResult> { pub(crate) fn event_filter_spec(value: &Bound<'_, PyAny>) -> PyResult { let family: Bound<'_, PyAny> = native_field(value, "family")?; Ok(EventFilterSpec { - invocation_id: optional_text(&native_field(value, "invocation_id")?)?, - run_id: optional_text(&native_field(value, "run_id")?)?, - producer: optional_text(&native_field(value, "producer")?)?, + invocation_id: nullable_text(&native_field(value, "invocation_id")?)?, + run_id: nullable_text(&native_field(value, "run_id")?)?, + producer: nullable_text(&native_field(value, "producer")?)?, event_types: texts(&native_field(value, "event_types")?)?, family: if family.is_none() { None @@ -199,7 +192,7 @@ pub(crate) fn run_filter_spec(value: &Bound<'_, PyAny>) -> PyResult>()?; Ok(RunFilterSpec { - invocation_id: optional_text(&native_field(value, "invocation_id")?)?, + invocation_id: nullable_text(&native_field(value, "invocation_id")?)?, statuses, created_at_start: filter_time(&native_field(value, "created_at_start")?)?, created_at_end: filter_time(&native_field(value, "created_at_end")?)?, @@ -214,9 +207,9 @@ pub(crate) fn known_event(event: &Bound<'_, PyAny>) -> PyResult { /// The `event_id` a known event carries or an opaque envelope holds as a string. pub(crate) fn event_id_of(event: &Bound<'_, PyAny>) -> PyResult> { if known_event(event)? { - return text_of(&native_field(event, "event_id")?); + return optional_text(&native_field(event, "event_id")?); } - text_of(&raw_field(event, "event_id")?) + optional_text(&raw_field(event, "event_id")?) } fn raw_field<'py>(event: &Bound<'py, PyAny>, name: &str) -> PyResult> { @@ -238,7 +231,7 @@ pub(crate) fn event_from_json<'py>(payload: &Bound<'py, PyAny>) -> PyResult) -> PyResult> { let py: Python<'_> = event.py(); - let Some(text) = text_of(&raw_field(event, "occurred_at")?)? else { + let Some(text) = optional_text(&raw_field(event, "occurred_at")?)? else { return Ok(None); }; let Some(parsed) = parsed_iso(py, &text)? else { @@ -259,7 +252,7 @@ pub(crate) fn envelope_of(event: &Bound<'_, PyAny>) -> PyResult { if known_event(event)? { envelope.schema_version = native_field(event, "schema_version")?.extract()?; for (slot, name) in envelope.text_fields.iter_mut().zip(ENVELOPE_TEXT_FIELDS) { - *slot = optional_text(&native_field(event, name)?)?; + *slot = nullable_text(&native_field(event, name)?)?; } envelope.occurred_at = Some(utc_time(&native_field(event, "occurred_at")?)?); return Ok(envelope); @@ -267,7 +260,7 @@ pub(crate) fn envelope_of(event: &Bound<'_, PyAny>) -> PyResult { envelope.schema_version = exact_int(&raw_field(event, "schema_version")?).unwrap_or(DEFAULT_SCHEMA_VERSION); for (slot, name) in envelope.text_fields.iter_mut().zip(ENVELOPE_TEXT_FIELDS) { - *slot = text_of(&raw_field(event, name)?)?.filter(|text| !text.is_empty()); + *slot = optional_text(&raw_field(event, name)?)?.filter(|text| !text.is_empty()); } envelope.occurred_at = opaque_occurred_at(event)?; Ok(envelope) @@ -313,9 +306,9 @@ pub(crate) fn run_row(record: &Bound<'_, PyAny>) -> PyResult { is_complete: native_field(record, "is_complete")?.is_truthy()?, last_event_cursor: native_field(record, "last_event_cursor")?.extract()?, last_storage_order: native_field(record, "last_storage_order")?.extract()?, - command: optional_text(&native_field(record, "command")?)?, - target: optional_text(&native_field(record, "target")?)?, - environment: optional_text(&native_field(record, "environment")?)?, + command: nullable_text(&native_field(record, "command")?)?, + target: nullable_text(&native_field(record, "target")?)?, + environment: nullable_text(&native_field(record, "environment")?)?, started_at: optional_time("started_at")?, ended_at: optional_time("ended_at")?, }) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/functions.rs b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/functions.rs index 9d0ccb7e3c..1a66d2882b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/functions.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/functions.rs @@ -5,6 +5,7 @@ use pyo3::prelude::{ wrap_pyfunction, }; use pyo3::types::PyTuple; +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use sqlbuild_state::execution_history::main::project_runs::project_runs; use sqlbuild_state::execution_history::main::validate_filter::validate_filter; use sqlbuild_state::execution_history::main::validate_page::validate_page; @@ -15,7 +16,7 @@ use sqlbuild_state::execution_history::models::FilterSpec; use crate::bindings::_helpers::execution_history::appends::{event_content, event_id}; use crate::bindings::_helpers::execution_history::conversion::{ checked, event_filter_spec, exact_int, projection_facts, run_filter_spec, run_records, - run_rows, text_of, utc_zone, + run_rows, utc_zone, }; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -71,7 +72,7 @@ fn append_and_project<'py>( fn validate_stored_history_event(record: &Bound<'_, PyAny>) -> Result<(), PyErr> { let py: Python<'_> = record.py(); let storage_order: i64 = native_field(record, "storage_order")?.extract()?; - let cursor: String = text_of(&native_field(record, "cursor")?)?.unwrap_or_default(); + let cursor: String = optional_text(&native_field(record, "cursor")?)?.unwrap_or_default(); let received_at_is_utc: bool = utc_zone(&native_field(record, "received_at")?)?; checked( py, @@ -105,9 +106,9 @@ fn validate_history_page(page: &Bound<'_, PyAny>, is_event_page: bool) -> Result let records: Bound<'_, PyAny> = native_field(page, "records")?; let has_records: bool = records.is_truthy()?; let next_cursor: Bound<'_, PyAny> = native_field(page, "next_cursor")?; - let next_text: Option = text_of(&next_cursor)?; + let next_text: Option = optional_text(&next_cursor)?; let last_text: Option = if is_event_page && has_records { - text_of(&native_field(&records.get_item(-1)?, "cursor")?)? + optional_text(&native_field(&records.get_item(-1)?, "cursor")?)? } else { None }; diff --git a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/postgres.rs b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/postgres.rs index 596d85fb3d..be8a2411f6 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/postgres.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/postgres.rs @@ -1,5 +1,6 @@ //! `PostgresExecutionHistory`: deployed PostgreSQL event-log and run-projection storage. +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use std::sync::OnceLock; use std::sync::atomic::{AtomicBool, AtomicI64, Ordering}; @@ -41,8 +42,8 @@ use sqlbuild_state::execution_history::types::UtcTime; use crate::bindings::_helpers::execution_history::appends::prepared_batch; use crate::bindings::_helpers::execution_history::conversion::{ checked, event_filter_spec, exact_int, history_error_of_kind, new_namespace, now, - optional_text, parsed_status, projection_facts, rejection, run_filter_spec, run_records, - run_rows, storage_error, stored_event, text_of, utc, utc_time, + nullable_text, parsed_status, projection_facts, rejection, run_filter_spec, run_records, + run_rows, storage_error, stored_event, utc, utc_time, }; use crate::bindings::_helpers::execution_history::statements::{ column, execute, execute_plain, execute_query, fetch_all, fetch_one, tuple_of, @@ -201,7 +202,8 @@ impl PostgresExecutionHistory { if history_error_of_kind(py, &error, STORAGE_ERROR)? || !driver_failure(py, &error)? { return Err(error); } - let sqlstate: Option = text_of(&native_field(error.value(py), "sqlstate")?)?; + let sqlstate: Option = + optional_text(&native_field(error.value(py), "sqlstate")?)?; if retries_transaction(sqlstate.as_deref(), attempts, max_retries) { attempts += 1; continue; @@ -281,7 +283,7 @@ impl PostgresExecutionHistory { execute_plain(active, POSTGRES_NAMESPACE)?; let row = fetch_one(active)?; let namespace = match row { - Some(row) => text_of(&row.get_item("storage_namespace")?)?, + Some(row) => optional_text(&row.get_item("storage_namespace")?)?, None => None, }; namespace.ok_or_else(|| storage_error(py, NAMESPACE_MISSING)) @@ -299,7 +301,7 @@ impl PostgresExecutionHistory { "PostgreSQL event timestamp is invalid", )?; let payload: Bound<'py, PyAny> = column(row, "payload_json")?; - if text_of(&payload)?.is_none() { + if optional_text(&payload)?.is_none() { return Err(storage_error( py, "PostgreSQL canonical event content is invalid", @@ -413,7 +415,7 @@ impl PostgresExecutionHistory { let Some(cursor) = cursor.filter(|cursor| !cursor.is_none()) else { return Ok(None); }; - let text: String = text_of(cursor)?.unwrap_or_default(); + let text: String = optional_text(cursor)?.unwrap_or_default(); let namespace: String = Self::namespace_in(slf, None)?; let decoded = checked(py, decoded_run_cursor(Dialect::Postgres, &text, &namespace))?; let invalid = || rejection(py, HistoryErrorKind::InvalidCursor, RUN_CURSOR_TIMESTAMP); @@ -496,7 +498,7 @@ impl PostgresExecutionHistory { Ok(Some(default)) }; let settings = PostgresSettings { - dsn: text_of(dsn)?, + dsn: optional_text(dsn)?, connect_timeout_seconds: setting( "connect_timeout_seconds", POSTGRES_CONNECT_TIMEOUT_SECONDS, @@ -636,7 +638,7 @@ impl PostgresExecutionHistory { let after: i64 = match after_cursor.filter(|cursor| !cursor.is_none()) { None => 0, Some(cursor) => { - let text: String = text_of(cursor)?.unwrap_or_default(); + let text: String = optional_text(cursor)?.unwrap_or_default(); let namespace: String = Self::namespace_in(slf, None)?; let position: i64 = checked( py, @@ -688,7 +690,7 @@ impl PostgresExecutionHistory { ) -> PyResult> { let py: Python<'py> = slf.py(); slf.get().ensure_open(py)?; - let run_id: Option = optional_text(run_id)?; + let run_id: Option = nullable_text(run_id)?; let params: Vec = vec![run_id.map_or(SqlParam::Null, SqlParam::Text)]; let rows = Self::read_rows( slf, @@ -940,8 +942,8 @@ impl PostgresExecutionHistory { "PostgreSQL event append did not produce a durable fact", )); }; - let digest: Option = text_of(&column(&row, "content_digest")?)?; - let payload: Option = text_of(&column(&row, "payload_json")?)?; + let digest: Option = optional_text(&column(&row, "content_digest")?)?; + let payload: Option = optional_text(&column(&row, "payload_json")?)?; checked( py, validate_stored_content(event, (digest.as_deref(), payload.as_deref())), diff --git a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/sqlite.rs b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/sqlite.rs index 128ca5f191..509575ace2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/execution_history/sqlite.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/execution_history/sqlite.rs @@ -1,5 +1,6 @@ //! `SQLiteExecutionHistory`: project-local SQLite event-log and run-projection storage. +use sqlbuild_python_base::boundary::main::optional_text::optional_text; use std::fs::DirBuilder; use std::io::ErrorKind; use std::path::Path; @@ -43,9 +44,9 @@ use sqlbuild_state::execution_history::types::UtcTime; use crate::bindings::_helpers::execution_history::appends::prepared_batch; use crate::bindings::_helpers::execution_history::conversion::{ checked, event_filter_spec, exact_int, history_error_of_kind, new_namespace, now, - optional_text, parsed_iso, parsed_status, projection_facts, python_params, rejection, + nullable_text, parsed_iso, parsed_status, projection_facts, python_params, rejection, run_filter_spec, run_records, run_rows, storage_error, storage_error_from, stored_event, - text_of, utc_time, + utc_time, }; use crate::bindings::_helpers::execution_history::statements::{ column, execute, execute_plain, execute_query, fetch_one, tuple_of, @@ -171,9 +172,9 @@ fn stored_run(row: &Bound<'_, PyAny>) -> PyResult { is_complete: column(row, "is_complete")?.is_truthy()?, last_event_cursor: column(row, "last_event_cursor")?.extract()?, last_storage_order: column(row, "last_storage_order")?.extract()?, - command: optional_text(&column(row, "command")?)?, - target: optional_text(&column(row, "target")?)?, - environment: optional_text(&column(row, "environment")?)?, + command: nullable_text(&column(row, "command")?)?, + target: nullable_text(&column(row, "target")?)?, + environment: nullable_text(&column(row, "environment")?)?, started_at: optional_timestamp(&column(row, "started_at")?)?, ended_at: optional_timestamp(&column(row, "ended_at")?)?, }) @@ -273,7 +274,7 @@ impl SqliteExecutionHistory { return Ok(0); }; let invalid = || storage_error(py, "SQLite history schema metadata is invalid"); - match text_of(&value)? { + match optional_text(&value)? { Some(text) => text.trim().parse::().map_err(|_| invalid()), None => exact_int(&value).ok_or_else(invalid), } @@ -350,8 +351,10 @@ impl SqliteExecutionHistory { )?)?; let row: Bound<'py, PyAny> = match existing { Some(existing) => { - let digest: Option = text_of(&column(&existing, "content_digest")?)?; - let payload: Option = text_of(&column(&existing, "payload_json")?)?; + let digest: Option = + optional_text(&column(&existing, "content_digest")?)?; + let payload: Option = + optional_text(&column(&existing, "payload_json")?)?; checked( py, validate_stored_content(event, (digest.as_deref(), payload.as_deref())), @@ -431,7 +434,7 @@ impl SqliteExecutionHistory { if cursor.is_none() { return Ok(None); } - let text: String = text_of(cursor)?.unwrap_or_default(); + let text: String = optional_text(cursor)?.unwrap_or_default(); let namespace: String = Self::namespace(connection)?; let decoded = checked(py, decoded_run_cursor(Dialect::Sqlite, &text, &namespace))?; let invalid_timestamp = @@ -808,7 +811,8 @@ impl SqliteExecutionHistory { let Some(result) = fetch_one(&execute_plain(&connection, SQLITE_QUICK_CHECK)?)? else { return Ok(false); }; - if text_of(&result.get_item(0)?)?.as_deref() != Some(SQLITE_HEALTHY_CHECK_RESULT) { + if optional_text(&result.get_item(0)?)?.as_deref() != Some(SQLITE_HEALTHY_CHECK_RESULT) + { return Ok(false); } let version: i64 = slf.call_method0("get_schema_version")?.extract()?; @@ -918,7 +922,7 @@ impl SqliteExecutionHistory { let Some(cursor) = cursor.filter(|cursor| !cursor.is_none()) else { return Ok(0); }; - let text: String = text_of(cursor)?.unwrap_or_default(); + let text: String = optional_text(cursor)?.unwrap_or_default(); let namespace: String = Self::namespace(connection)?; let position: i64 = checked( py, diff --git a/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs b/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs index 2d55857711..9e116fd109 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs @@ -1,11 +1,12 @@ //! Resolve `sqb format` selectors to the adapter, discovered inputs and selected files. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::BTreeSet; use std::fs; use std::path::{Path, PathBuf}; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::types::{PyBool, PyDict, PyFrozenSet, PyString, PyStringMethods, PyTuple}; +use pyo3::types::{PyBool, PyFrozenSet, PyString, PyStringMethods, PyTuple}; use sqlbuild_core::format_command::errors::FormatSelectorError; use sqlbuild_core::format_command::main::exact_selector_names::exact_selector_names; use sqlbuild_core::format_command::main::lint_sql_paths::lint_sql_paths; @@ -18,7 +19,6 @@ use sqlbuild_python_base::boundary::main::value_error::value_error; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::command_runtime::main::resolve_cli_adapter::resolve_cli_adapter; use sqlbuild_python_base::records::main::construct::enum_member::enum_member; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -54,15 +54,7 @@ struct Scope<'a, 'py> { } fn planner_error(py: Python<'_>, message: &str, code: &str) -> PyErr { - let raised = (|| -> PyResult> { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", code)?; - error_class(py, ErrorId::PlannerInput)?.call((message,), Some(&keywords)) - })(); - match raised { - Ok(instance) => PyErr::from_value(instance), - Err(failure) => failure, - } + new_error(py, ErrorId::PlannerInput, message, (Some(code), None)) } fn selector_error(py: Python<'_>, error: &FormatSelectorError) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs index b94e3b071f..f5db7771fb 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs @@ -1,5 +1,6 @@ //! `sqb freshness`: observe selected source freshness without writing state. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::BTreeSet; use pyo3::exceptions::PyValueError; @@ -36,7 +37,6 @@ use sqlbuild_python_project::project_snapshot::types::VerifiedRun; use sqlbuild_core::constants::SOURCE_FRESHNESS_TABLE_NAME as STATE_TABLE_NAME; use sqlbuild_python_base::native_host::main::host_entry::host_entry; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; const STALE_REQUIRES_STATE_MESSAGE: &str = "freshness --fail-on-stale requires --state"; @@ -58,15 +58,7 @@ fn keywords<'py>( } fn user_error(py: Python<'_>, (message, code): (&str, &str)) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, message, (Some(code), None)) } fn write(py: Python<'_>, text: &str) -> PyResult<()> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs index 89d973a5a0..71dac11d44 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs @@ -1,11 +1,12 @@ //! `sqb init`: scaffold a blank SQLBuild project and its agent skills. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::path::PathBuf; use pyo3::prelude::{ Bound, PyAny, PyAnyMethods, PyErr, PyModule, PyModuleMethods, PyResult, Python, }; -use pyo3::types::{PyDict, PyDictMethods, PyString}; +use pyo3::types::PyString; use pyo3::{pyfunction, wrap_pyfunction}; use sqlbuild_core::cli_text::models::CliStyle; use sqlbuild_core::constants::PROJECT_CONFIG_FILENAME as PROJECT_FILE; @@ -18,22 +19,13 @@ use crate::bindings::_helpers::workspace_commands::commands::update_sqlbuild_ski use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; const EXISTS_MESSAGE: &str = "sqlbuild_project.toml already exists in this directory"; fn exists_error(py: Python<'_>) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", "C900")?; - error_class(py, ErrorId::CliUser)?.call((EXISTS_MESSAGE,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, EXISTS_MESSAGE, (Some("C900"), None)) } /// Create a minimal SQLBuild project in the project directory. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs index dc2ce178c1..19a279f42a 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs @@ -24,6 +24,7 @@ use sqlbuild_core::janitor_text::main::render_janitor_completion::render_janitor use sqlbuild_core::janitor_text::main::render_janitor_plan::render_janitor_plan; use sqlbuild_core::janitor_text::main::validate_janitor_settings::validate_janitor_settings; use sqlbuild_core::janitor_text::models::{JanitorOutcome, JanitorPlanText, JanitorRunText}; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::time::Instant; use crate::bindings::_helpers::cli::machine_output::{ @@ -39,7 +40,6 @@ use crate::bindings::_helpers::janitor::janitor_plan::{janitor_plan_text, janito use crate::bindings::_helpers::janitor::janitor_progress::JanitorProgressPrinter; use crate::bindings::_helpers::scenario_command::setup::stream_isatty; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record::new_record; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -72,15 +72,12 @@ fn keywords<'py>( } fn settings_error(py: Python<'_>, error: JanitorSettingsError) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", error.code)?; - error_class(py, ErrorId::CliUser)?.call((error.message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + error.message, + (Some(error.code), None), + ) } fn write(stream: &Bound<'_, PyAny>, text: &str) -> PyResult<()> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs index 99e6f35fc4..7206c88587 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs @@ -1,5 +1,6 @@ //! `sqb lineage`: load or build the relation graph, select lineage, and print it. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; @@ -103,16 +104,12 @@ fn keywords<'py>( /// `CliUserError(message, code=..., help=...)`. fn user_error(py: Python<'_>, error: LineageError) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", error.code)?; - options.set_item("help", error.help)?; - error_class(py, ErrorId::CliUser)?.call((error.message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &error.message, + (Some(error.code), error.help.as_deref()), + ) } fn strings(value: &Bound<'_, PyAny>) -> PyResult> { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs b/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs index 93aed88937..10315d480b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs @@ -19,8 +19,7 @@ use sqlbuild_host::entries::models::AdapterHost; use sqlbuild_python_base::boundary::models::KeywordArguments; use sqlbuild_python_base::native_host::main::host_entry::host_entry; -use sqlbuild_python_base::records::main::construct::error_class::error_class; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; @@ -137,11 +136,11 @@ fn preserved_source_namespace( ), ) { Ok(()) => Ok(()), - Err(AssemblyError::CompileInput { message, help }) => Err(new_helped_error( + Err(AssemblyError::CompileInput { message, help }) => Err(new_error( source.py(), ErrorId::CompileInput, - (message, COMPILE_INPUT_CODE), - help.as_deref(), + &message, + (Some(COMPILE_INPUT_CODE), help.as_deref()), )), Err(other) => Err(PyValueError::new_err(format!("{other:?}"))), } @@ -283,22 +282,15 @@ impl<'py> LoadProject<'py> { } fn unknown_selector(py: Python<'_>, error: &UnknownLoadSelector) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", UNKNOWN_SELECTOR_CODE)?; - options.set_item("help", UNKNOWN_SELECTOR_HELP)?; - error_class(py, ErrorId::CliUser)?.call( - (format!( - "sqb load selector '{}' does not match any managed source or loader", - error.name - ),), - Some(&options), - ) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &format!( + "sqb load selector '{}' does not match any managed source or loader", + error.name + ), + (Some(UNKNOWN_SELECTOR_CODE), Some(UNKNOWN_SELECTOR_HELP)), + ) } /// `value.strip()` when it is a string with non-blank text, else `None`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs b/crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs index 9e65260a9d..a5a7ae150d 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs @@ -1,5 +1,6 @@ //! `sqb query`: run ad hoc SQL on the project connection and print the rows. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::time::Duration; use pyo3::exceptions::PyException; @@ -41,20 +42,7 @@ const RUNNING_QUERY_MESSAGE: &str = "Running query..."; /// A `CliUserError` with its code and optional help. fn user_error(py: Python<'_>, message: &str, code: Option<&str>, help: Option<&str>) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - if let Some(code) = code { - options.set_item("code", code)?; - } - if let Some(help) = help { - options.set_item("help", help)?; - } - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error(py, ErrorId::CliUser, message, (code, help)) } fn empty_sql(py: Python<'_>) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/recall/command.rs b/crates/sqlbuild-python/src/bindings/_helpers/recall/command.rs index b70d1e9949..84fe6143fe 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/recall/command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/recall/command.rs @@ -40,7 +40,7 @@ use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::types::ErrorId; fn user_error(py: Python<'_>, message: &str, code: &str) -> PyErr { - new_error(py, ErrorId::CliUser, message.to_owned(), code) + new_error(py, ErrorId::CliUser, message, (Some(code), None)) } fn store_failure(py: Python<'_>, error: &StoreError) -> PyErr { diff --git a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs index 547d358d70..1f09dfe1ee 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs @@ -1,5 +1,6 @@ //! `sqb rename` and `sqb mv`: plan from compiler facts, verify in a scratch copy, then write. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::cell::RefCell; use std::collections::{BTreeSet, HashMap}; use std::path::{Path, PathBuf}; @@ -65,16 +66,12 @@ fn imported<'py>(py: Python<'py>, module: &str, name: &str) -> PyResult, (message, code, help): (String, &str, Option)) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", code)?; - options.set_item("help", help)?; - error_class(py, ErrorId::CliUser)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &message, + (Some(code), help.as_deref()), + ) } /// The Python exception a native refactoring failure becomes. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/comparison.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/comparison.rs index 4419e0c112..57dcaef5a2 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/comparison.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/comparison.rs @@ -21,7 +21,7 @@ use crate::bindings::_helpers::dagster_invocation::access::string_tuple as texts use crate::bindings::_helpers::diff_report::command::target_max_full_rows; use crate::bindings::_helpers::diff_report::facts::diff_facts; use crate::bindings::_helpers::diff_report::support::{error_text, matches_class}; -use crate::bindings::_helpers::execution_history::conversion::optional_text; +use crate::bindings::_helpers::execution_history::conversion::nullable_text; use crate::bindings::_helpers::execution_history::statements::fetch_one; use crate::bindings::_helpers::review_command::planning::ReviewSettings; use crate::bindings::_helpers::review_command::support::review_error; @@ -556,7 +556,7 @@ pub(crate) fn prepare_sides<'py>( right: pipeline.get_item(1)?, left, limits, - bounded: optional_text(&native_field(context.request, "bounded")?)?, + bounded: nullable_text(&native_field(context.request, "bounded")?)?, against_has, })) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs index 1fc761e725..e35bbe3e74 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/planning.rs @@ -22,7 +22,7 @@ use sqlbuild_config::project::models::ReviewConfig; use crate::bindings::_helpers::change_selection::base_snapshot::{base_comparison, base_variant}; use crate::bindings::_helpers::change_selection::definition_snapshot::project_wide_keys; use crate::bindings::_helpers::change_selection::selection::{ChangedProject, changed_project}; -use crate::bindings::_helpers::execution_history::conversion::optional_text; +use crate::bindings::_helpers::execution_history::conversion::nullable_text; use crate::bindings::_helpers::review_command::support::review_error; use sqlbuild_python_base::boundary::main::keywords::keywords; use sqlbuild_python_base::build_command::main::boolean::boolean; @@ -107,7 +107,7 @@ pub(crate) fn review_settings( ) -> PyResult { let py: Python<'_> = request.py(); let config: ReviewConfig = configured_review(project_dir)?; - let since: String = match optional_text(&native_field(request, "since")?)? { + let since: String = match nullable_text(&native_field(request, "since")?)? { Some(since) => since, None if configured_git_base_ref(project_dir)?.is_some() => BASE_REF_ALIAS.to_owned(), None => { @@ -120,7 +120,7 @@ pub(crate) fn review_settings( } }; let against: String = - match optional_text(&native_field(request, "against")?)?.or(config.against.clone()) { + match nullable_text(&native_field(request, "against")?)?.or(config.against.clone()) { Some(against) => against, None => { return Err(setting_error( @@ -156,7 +156,7 @@ pub(crate) fn review_settings( )); }; let downstream: Option = - optional_text(&native_field(request, "downstream")?)?.or(config.downstream.clone()); + nullable_text(&native_field(request, "downstream")?)?.or(config.downstream.clone()); let policy: DownstreamPolicy = match downstream.as_deref() { None => DownstreamPolicy::Critical, Some(value) => parse_downstream_policy(value).ok_or_else(|| { @@ -245,7 +245,7 @@ fn model_node(model: &Bound<'_, PyAny>, critical_tags: &[String]) -> PyResult) -> PyResult> { - optional_text(&native_field(destination, "database")?) + nullable_text(&native_field(destination, "database")?) } /// Dependency order over `nodes`, ties broken by name. @@ -535,7 +535,7 @@ pub(crate) fn review_project<'py>( let changes_json: Value = serde_json::from_str(&changed.json((0, &[]))) .map_err(|error| pyo3::exceptions::PyValueError::new_err(error.to_string()))?; let target_database: Option = - optional_text(&native_field(&project, "effective_target_database")?)? + nullable_text(&native_field(&project, "effective_target_database")?)? .filter(|database| !database.eq_ignore_ascii_case(PRESERVE_DATABASE)); let review = ReviewProject { changed_declarations: changed_declarations(&changed.changes), @@ -552,7 +552,7 @@ pub(crate) fn review_project<'py>( stateful, databases, target_database, - target_schema: optional_text(&native_field(&project, "effective_target_schema")?)?, + target_schema: nullable_text(&native_field(&project, "effective_target_schema")?)?, }; Ok((review, (discovered, adapter, graph))) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs b/crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs index dbf332d5e6..d615eec00c 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs @@ -1,22 +1,22 @@ //! Errors and progress lines shared by the `sqb review` phases. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::time::Instant; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; -use pyo3::types::{PyDict, PyDictMethods, PyTypeMethods}; +use pyo3::types::PyTypeMethods; use sqlbuild_analysis::janitor_planning::models::ArchiveTimestamp; use sqlbuild_analysis::review_command::errors::ReviewPlanError; use sqlbuild_analysis::review_command::models::ReviewFailure; use sqlbuild_host::entries::models::ExecutorHost; use crate::bindings::_helpers::clone::clone_progress::write_line; -use crate::bindings::_helpers::execution_history::conversion::optional_text; +use crate::bindings::_helpers::execution_history::conversion::nullable_text; use crate::bindings::_helpers::janitor::janitor_keys::{now_utc, timestamp_fields}; use sqlbuild_python_base::boundary::main::call_with::call_with; use sqlbuild_python_base::boundary::main::imported::imported; use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::native_host::main::host_entry::host_entry; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; @@ -27,16 +27,12 @@ const UNEXPLAINED_FAILURE: &str = "review failed"; /// `class(message, code=code, help=help)`. fn raised(py: Python<'_>, class: ErrorId, failure: &ReviewFailure) -> PyErr { - let instance = (|| -> PyResult> { - let keywords: Bound<'_, PyDict> = PyDict::new(py); - keywords.set_item("code", failure.code.as_str())?; - keywords.set_item("help", failure.help.as_deref())?; - error_class(py, class)?.call((failure.message.as_str(),), Some(&keywords)) - })(); - match instance { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + class, + &failure.message, + (Some(&failure.code), failure.help.as_deref()), + ) } /// `CliUserError(message, code=code, help=help)`. @@ -151,5 +147,5 @@ pub(crate) fn invocation_id(py: Python<'_>) -> PyResult> { if identity.is_none() { return Ok(None); } - optional_text(&native_field(&identity, "invocation_id")?) + nullable_text(&native_field(&identity, "invocation_id")?) } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs index 0dc66fee49..c7cd050861 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs @@ -1,5 +1,6 @@ //! Shared `sqb scenario` preparation: project, namespace, adapters, compile and selection. +use sqlbuild_python_base::records::main::construct::new_error::new_error; use std::path::PathBuf; use pyo3::prelude::{Bound, PyAny, PyAnyMethods, PyErr, PyResult, Python}; @@ -31,7 +32,6 @@ use sqlbuild_python_base::boundary::main::within::within; use sqlbuild_python_base::command_runtime::main::resolve_cli_adapter::resolve_cli_adapter; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::presentation_text::main::stdout_supports_color::stdout_supports_color; -use sqlbuild_python_base::records::main::construct::error_class::error_class; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::main::fields::replaced_keywords::replaced_keywords; @@ -58,16 +58,12 @@ pub(crate) fn optional_text<'py>(py: Python<'py>, value: Option<&str>) -> Bound< /// `CliUserError(message, code=..., help=...)`. pub(crate) fn cli_user_error(py: Python<'_>, error: ScenarioCommandError) -> PyErr { - let raised: PyResult> = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", error.code)?; - options.set_item("help", error.help)?; - error_class(py, ErrorId::CliUser)?.call((error.message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::CliUser, + &error.message, + (Some(error.code), error.help.as_deref()), + ) } /// The progress stream: `write` then `flush`. diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/python_tests.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/python_tests.rs index 9ddd412a8b..0b42953e34 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/python_tests.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/python_tests.rs @@ -18,7 +18,7 @@ use sqlbuild_python_base::build_progress::main::terminal::write::write; use sqlbuild_python_base::native_host::main::flush_console::flush_console; use sqlbuild_python_base::native_host::main::module_installed::module_installed; use sqlbuild_python_base::native_host::main::python_executable::python_executable; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::fields::field::field as native_field; use sqlbuild_python_base::records::types::ErrorId; use sqlbuild_python_compile::compile_driver::main::setup::project_graph::project_graph; @@ -111,24 +111,27 @@ pub(crate) fn selected_python_tests( _ => modules, }; if native_field(request, "python_only")?.is_truthy()? && selected.is_empty() { - return Err(new_helped_error( + return Err(new_error( py, ErrorId::PlannerInput, - ("no Python tests found".to_owned(), PYTHON_TESTS_INPUT_CODE), - Some( - "add test_*.py modules under tests/python/ or tests/providers/, mirroring the code they test", + "no Python tests found", + ( + Some(PYTHON_TESTS_INPUT_CODE), + Some( + "add test_*.py modules under tests/python/ or tests/providers/, mirroring the code they test", + ), ), )); } if !selected.is_empty() && !module_installed(py, PYTEST_MODULE)? { - return Err(new_helped_error( + return Err(new_error( py, ErrorId::PlannerInput, + "Python tests found but pytest isn't installed", ( - "Python tests found but pytest isn't installed".to_owned(), - PYTHON_TESTS_INPUT_CODE, + Some(PYTHON_TESTS_INPUT_CODE), + Some("install the dev dependencies, or run `sqb test --sql`"), ), - Some("install the dev dependencies, or run `sqb test --sql`"), )); } Ok(selected) diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs index a28e34fba2..50b565c96b 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs @@ -60,8 +60,7 @@ use sqlbuild_python_base::build_progress::main::progress::current_native_progres use sqlbuild_python_base::build_progress::main::transient_status::status_reporter::status_reporter; use sqlbuild_python_base::native_host::main::host_entry::host_entry; use sqlbuild_python_base::native_host::types::ReadResult; -use sqlbuild_python_base::records::main::construct::error_class::error_class; -use sqlbuild_python_base::records::main::construct::new_helped_error::new_helped_error; +use sqlbuild_python_base::records::main::construct::new_error::new_error; use sqlbuild_python_base::records::main::construct::new_record_with::new_record_with; use sqlbuild_python_base::records::main::construct::record_class::record_class; use sqlbuild_python_base::records::main::fields::field::field as native_field; @@ -301,15 +300,12 @@ impl TestCallbackRelay { } fn unknown_case(py: Python<'_>, message: String) -> PyErr { - let raised = (|| { - let options: Bound<'_, PyDict> = PyDict::new(py); - options.set_item("code", UNKNOWN_CASE_CODE)?; - error_class(py, ErrorId::PlannerInput)?.call((message,), Some(&options)) - })(); - match raised { - Ok(error) => PyErr::from_value(error), - Err(error) => error, - } + new_error( + py, + ErrorId::PlannerInput, + &message, + (Some(UNKNOWN_CASE_CODE), None), + ) } /// Compile the selected tests and refuse a `--case` that matched none of them. @@ -712,28 +708,30 @@ pub(crate) fn run_test<'py>( let (worker, discovered) = verified.unzip(); let inspect_only: bool = native_field(request, "inspect")?.is_truthy()?; if native_field(request, "python_only")?.is_truthy()? && worker.is_some() { - return Err(new_helped_error( + return Err(new_error( py, ErrorId::PlannerInput, + "--python cannot run on a server location", ( - "--python cannot run on a server location".to_owned(), - PYTHON_TESTS_INPUT_CODE, + Some(PYTHON_TESTS_INPUT_CODE), + Some( + "runs on a server location run SQL tests only; run `sqb test --python` locally", + ), ), - Some("runs on a server location run SQL tests only; run `sqb test --python` locally"), )); } if native_field(request, "python_only")?.is_truthy()? && (inspect_only || !native_field(request, "since")?.is_none()) { - return Err(new_helped_error( + return Err(new_error( py, ErrorId::PlannerInput, + "--python cannot be combined with --inspect or --since", ( - "--python cannot be combined with --inspect or --since".to_owned(), - PYTHON_TESTS_INPUT_CODE, - ), - Some( - "--inspect and --since apply to SQL tests only; run `sqb test --python` without them", + Some(PYTHON_TESTS_INPUT_CODE), + Some( + "--inspect and --since apply to SQL tests only; run `sqb test --python` without them", + ), ), )); } diff --git a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs index ac94e0c23f..f2af310ab8 100644 --- a/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs +++ b/crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/timeouts.rs @@ -63,7 +63,12 @@ impl RunTimeout { } fn invalid(py: Python<'_>, message: String) -> PyErr { - new_error(py, ErrorId::CompileInput, message, INVALID_TIMEOUT_CODE) + new_error( + py, + ErrorId::CompileInput, + &message, + (Some(INVALID_TIMEOUT_CODE), None), + ) } fn limit_seconds(text: &str) -> Option> { diff --git a/fensu.toml b/fensu.toml index 2fe267411b..bb67834d42 100644 --- a/fensu.toml +++ b/fensu.toml @@ -1670,7 +1670,7 @@ select = ["FPRS", "XSB072", "XSB073", "XSB075", "XSB076", "XSB077", "XSB078", "X [[targets.rust.threshold_overrides]] paths = ["crates/sqlbuild-python/Cargo.toml"] -thresholds = { max_crate_code_lines = 66831 } +thresholds = { max_crate_code_lines = 66709 } reason = "The Python bindings crate is above the code-line limit; this caps it at its current size until it is split into crates by area. Lower the cap as code moves out." [[targets.rust.threshold_overrides]] @@ -2188,7 +2188,7 @@ pending_budgets = [ "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/pipeline_entries.rs=1", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/project.rs=7", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/python_plan_entries.rs=1", - "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs=7", + "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs=6", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs=4", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/stages/analysis.rs=8", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/stages/analysis_cache.rs=20", @@ -2219,7 +2219,7 @@ pending_budgets = [ "crates/sqlbuild-python-compile/src/frontier/_helpers/stage_capture.rs=9", "crates/sqlbuild-python-compile/src/frontier/main/write_plan_capture.rs=5", "crates/sqlbuild-python-compile/src/hand_built/_helpers/compiled_model.rs=3", - "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs=4", + "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs=2", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_calls.rs=4", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_contracts.rs=3", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_external.rs=4", @@ -2228,7 +2228,7 @@ pending_budgets = [ "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop_host.rs=1", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_macros.rs=6", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_named.rs=5", - "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs=7", + "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_opt_out.rs=6", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_python_hooks.rs=1", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_schema.rs=1", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model_loop/model_loop_visibility.rs=5", @@ -2259,9 +2259,7 @@ pending_budgets = [ "crates/sqlbuild-python-compile/src/project_assembly/_helpers/declared_relations.rs=1", "crates/sqlbuild-python-compile/src/project_assembly/_helpers/native_resources.rs=3", "crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_checks.rs=1", - "crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs=1", "crates/sqlbuild-python-compile/src/rules/_helpers/checking/findings.rs=6", - "crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs=1", "crates/sqlbuild-python-compile/src/rules/_helpers/checking/project_tree_queries.rs=8", "crates/sqlbuild-python-compile/src/rules/_helpers/checking/rows.rs=5", "crates/sqlbuild-python-compile/src/rules/_helpers/configuration/builtin_catalogue.rs=2", @@ -2315,7 +2313,7 @@ pending_budgets = [ "crates/sqlbuild-python-front/src/authored_values/models.rs=2", "crates/sqlbuild-python-front/src/compile_attachment/_helpers/effective_config.rs=1", "crates/sqlbuild-python-front/src/compile_attachment/main/build_effective_settings.rs=3", - "crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs=2", + "crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs=1", "crates/sqlbuild-python-front/src/contracts/_helpers/effective_config.rs=2", "crates/sqlbuild-python-front/src/contracts/_helpers/spec_resolution.rs=3", "crates/sqlbuild-python-front/src/contracts/main/resolve_effective_collection_rendering.rs=1", @@ -2428,7 +2426,7 @@ pending_budgets = [ "crates/sqlbuild-python-front/src/sqltext/_helpers/static_sql.rs=1", "crates/sqlbuild-python-front/src/sqltext/models.rs=1", "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/events.rs=1", - "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs=4", + "crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs=3", "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_io.rs=6", "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_projections.rs=0", "crates/sqlbuild-python-front/src/state_rows/_helpers/migrations/migration_rows.rs=5", @@ -2581,7 +2579,7 @@ pending_budgets = [ "crates/sqlbuild-python-project/src/graph/_helpers/nodes/execution_gates.rs=1", "crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_lifecycle.rs=0", "crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_node_graph.rs=3", - "crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs=5", + "crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs=4", "crates/sqlbuild-python-project/src/graph/main/nodes/model_python_hook_names.rs=1", "crates/sqlbuild-python-project/src/graph/main/nodes/sql_ref_key.rs=1", "crates/sqlbuild-python-project/src/graph/main/python_nodes/build_python_sql_run_lifecycle.rs=2", @@ -2629,7 +2627,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/build_command/invocation.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/build_command/lifecycle.rs=21", "crates/sqlbuild-python/src/bindings/_helpers/build_command/planning.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs=5", + "crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/build_progress/audit_progress.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/build_progress/build_callbacks.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/build_progress/nested_progress.rs=4", @@ -2637,17 +2635,17 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/build_progress/progress_reporters.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/build_progress/progress_text.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/build_progress/result_text.rs=10", - "crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs=20", + "crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/check/check_core.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/check/check_results.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/cli/argv.rs=18", - "crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs=18", + "crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs=17", "crates/sqlbuild-python/src/bindings/_helpers/cli/entry.rs=27", "crates/sqlbuild-python/src/bindings/_helpers/cli/namespace.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/cli/observability.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/cli/surrogates.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/cli/termination.rs=8", - "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs=11", + "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs=10", "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_execution.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_pipeline.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_progress.rs=5", @@ -2661,12 +2659,11 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/compile_driver/static_context.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/compute_logs/conversion.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/compute_logs/storage.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs=18", + "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs=17", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/write.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/bounds.rs=16", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/command.rs=11", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/refresh.rs=10", - "crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/cost_report/degradation.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/cost_report/functions.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/cost_report/records.rs=12", @@ -2681,15 +2678,15 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/auto_init.rs=10", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/command.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/debug.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs=8", + "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init_project.rs=26", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/support.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/dbt_events/stream.rs=0", - "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs=9", + "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/event_stream.rs=14", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/execution.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs=9", + "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs=1", + "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/orchestration.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline.rs=19", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs=12", @@ -2711,7 +2708,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/diff_report/facts.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/output.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/query.rs=17", - "crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs=6", + "crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/tolerances.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/dispatcher.rs=28", "crates/sqlbuild-python/src/bindings/_helpers/event_exporting/registration.rs=2", @@ -2725,24 +2722,24 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/format_command/command.rs=15", "crates/sqlbuild-python/src/bindings/_helpers/format_command/config.rs=1", "crates/sqlbuild-python/src/bindings/_helpers/format_command/run.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs=17", - "crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs=8", + "crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs=2", + "crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs=16", + "crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/init_command/scaffold.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_classification.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs=13", + "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs=12", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_facts.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_keys.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_old_names.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_phases.rs=17", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_plan.rs=4", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_planning.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs=12", + "crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs=11", "crates/sqlbuild-python/src/bindings/_helpers/load/dlt_destination.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/load/ingestr_command.rs=0", "crates/sqlbuild-python/src/bindings/_helpers/load/load_command.rs=16", "crates/sqlbuild-python/src/bindings/_helpers/load/load_progress.rs=17", - "crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs=3", + "crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/context.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/dispatcher.rs=31", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/records.rs=16", @@ -2751,7 +2748,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/plan_command/rules.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/query_command/dag.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/query_command/project.rs=2", - "crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs=14", + "crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/query_command/query_values.rs=5", "crates/sqlbuild-python/src/bindings/_helpers/recall/console.rs=6", "crates/sqlbuild-python/src/bindings/_helpers/recall/replacements.rs=8", @@ -2768,7 +2765,7 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/migrations.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/planner.rs=7", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/rule_shapes.rs=5", - "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs=24", + "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs=23", "crates/sqlbuild-python/src/bindings/_helpers/result_output/aggregation.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/result_output/checks.rs=0", "crates/sqlbuild-python/src/bindings/_helpers/result_output/documents.rs=13", @@ -2781,16 +2778,16 @@ pending_budgets = [ "crates/sqlbuild-python/src/bindings/_helpers/review_command/command.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/review_command/comparison.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/review_command/execution.rs=1", - "crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs=3", + "crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/capture_command.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/conversions.rs=3", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/presentation.rs=3", - "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs=14", + "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/snapshot_sync.rs=2", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/test_command.rs=13", "crates/sqlbuild-python/src/bindings/_helpers/scopes/scope_command.rs=8", "crates/sqlbuild-python/src/bindings/_helpers/seed_command/command.rs=14", - "crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs=97", + "crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs=96", "crates/sqlbuild-python/src/bindings/_helpers/workspace_commands/commands.rs=5", ] @@ -3308,10 +3305,6 @@ reason = "Each matches its own native class's attribute names to its own getters paths = ["crates/sqlbuild-python-project/src/compiled_views/_helpers/model_inputs/model_input_view.rs", "crates/sqlbuild-python-project/src/resource_views/_helpers/audit_views.rs", "crates/sqlbuild-python-project/src/resource_views/_helpers/function_views.rs", "crates/sqlbuild-python-project/src/resource_views/_helpers/seed_views.rs", "crates/sqlbuild-python-project/src/resource_views/_helpers/source_views.rs"] reason = "Each borrows its own record from the compiled project owner by index; only the borrow-and-read shape is alike." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-project/src/compiled_project/_helpers/project.rs", "crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs", "crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs", "crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs", "crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs"] -reason = "Each reads an optional text value from its own Python mapping; consolidating these readers across the binding crates is a separate change." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-project/src/compiled_views/models.rs"] reason = "Each getter reads its own cached projection through the view's shared read helper." @@ -3392,10 +3385,6 @@ reason = "Each builds a dict keyed by a field of its own records; only the loop paths = ["crates/sqlbuild-python-front/src/discovery/main/python_files/register_imported_python_nodes.rs", "crates/sqlbuild-python-project/src/planner_identity/main/register_graph.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/pipeline_phases.rs", "crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs"] reason = "Each bindings module registers its own functions and classes with the native module." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-project/src/compiled_project/main/text_value.rs", "crates/sqlbuild-python-project/src/compiled_views/_helpers/compiled_models/compiled_model_view.rs", "crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/audit_loop.rs", "crates/sqlbuild-python-compile/src/input_loops/_helpers/resources/resource_diagnostics.rs", "crates/sqlbuild-python-planner/src/plan_output/_helpers/python_identity.rs"] -reason = "Each reads an optional text value from its own Python mapping; consolidating these readers across the binding crates is a separate change." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-project/src/compiled_views/_helpers/project/project_view.rs", "crates/sqlbuild-python-project/src/graph/main/nodes/native_key.rs", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/compiled.rs", "crates/sqlbuild-python/src/bindings/_helpers/record_behaviours/macros.rs", "crates/sqlbuild-python-compile/src/rules/_helpers/configuration/catalogue.rs"] reason = "Each reads a resource key's type and name into its own native key; consolidating the key readers across the binding crates is a separate change." @@ -3428,10 +3417,6 @@ reason = "Each builds its own index from its own node list; only the index-build paths = ["crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs", "crates/sqlbuild-python-project/src/graph/main/project/project_graph.rs"] reason = "Each builds its own index from its own node list; only the index-building loop is alike." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-base/src/records/_helpers/native_classes/construct.rs", "crates/sqlbuild-python-front/src/compile_driver/_helpers/config_validation.rs", "crates/sqlbuild-python-project/src/graph/_helpers/python_nodes/python_selection.rs", "crates/sqlbuild-python/src/bindings/_helpers/build_command/policies.rs", "crates/sqlbuild-python/src/bindings/_helpers/check/check_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/cli/dispatch.rs", "crates/sqlbuild-python/src/bindings/_helpers/clone/clone_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs", "crates/sqlbuild-python/src/bindings/_helpers/cost_command/refusal.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_command/init.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/graph.rs", "crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs", "crates/sqlbuild-python/src/bindings/_helpers/diff_report/support.rs", "crates/sqlbuild-python/src/bindings/_helpers/format_command/selection.rs", "crates/sqlbuild-python/src/bindings/_helpers/freshness/freshness_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/init_command/command.rs", "crates/sqlbuild-python-compile/src/input_loops/_helpers/model/model_loop.rs", "crates/sqlbuild-python/src/bindings/_helpers/janitor/janitor_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/lineage/lineage_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/load/load_selection.rs", "crates/sqlbuild-python-compile/src/project_assembly/_helpers/syntax_validation.rs", "crates/sqlbuild-python/src/bindings/_helpers/query_command/query.rs", "crates/sqlbuild-python/src/bindings/_helpers/refactor/refactor_command.rs", "crates/sqlbuild-python/src/bindings/_helpers/review_command/support.rs", "crates/sqlbuild-python-compile/src/rules/_helpers/checking/native_header_parser.rs", "crates/sqlbuild-python/src/bindings/_helpers/scenario_command/setup.rs", "crates/sqlbuild-python/src/bindings/_helpers/sql_test_command/test_command.rs"] -reason = "Each builds its own error class's exception from a message; sharing one exception constructor across the binding crates is a separate change." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-project/src/resource_views/main/audit_reads/always_run.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/attached_target_kind.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/attached_target_name.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/definition_name.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/description.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/evidence_limit.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/evidence_sql.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/key.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/meta.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/name.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/references.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/scope_deps.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/severity.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/sql_body.rs", "crates/sqlbuild-python-project/src/resource_views/main/audit_reads/thresholds.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/arguments.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/body_sql.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/destination.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/fingerprint_destination.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/key.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/language.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/name.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/packages.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/relative_path.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/return_columns.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/returns.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/runtime_version.rs", "crates/sqlbuild-python-project/src/resource_views/main/function_reads/source_file_path.rs", "crates/sqlbuild-python-project/src/resource_views/main/seed_reads/external.rs", "crates/sqlbuild-python-project/src/resource_views/main/seed_reads/key.rs", "crates/sqlbuild-python-project/src/resource_views/main/seed_reads/name.rs", "crates/sqlbuild-python-project/src/resource_views/main/seed_reads/schema_entry.rs", "crates/sqlbuild-python-project/src/resource_views/main/source_reads/key.rs", "crates/sqlbuild-python-project/src/resource_views/main/source_reads/name.rs", "crates/sqlbuild-python-project/src/resource_views/main/source_reads/source_entry.rs", "crates/sqlbuild-python-project/src/resource_views/main/source_reads/source_file.rs"] reason = "Each getter reads its own attribute of a compiled resource, from the native view when the object is one and by attribute otherwise; only the view-or-attribute shape is alike." @@ -3632,10 +3617,6 @@ reason = "Each converts its own input into its own native or Python value; only paths = ["crates/sqlbuild-python-project/src/analysis_session/_helpers/stage_functions.rs", "crates/sqlbuild-python-planner/src/planner_identity/_helpers/metadata.rs"] reason = "Each converts its own input into its own native or Python value; only the conversion shape is alike." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-front/src/state_rows/_helpers/tables/state_tables.rs", "crates/sqlbuild-python-project/src/references/_helpers/source_relations.rs"] -reason = "Each builds its own error class's exception from a message; sharing one exception constructor across the binding crates is a separate change." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-front/src/discovery/main/records/discover_constant_files.rs", "crates/sqlbuild-python-front/src/discovery/main/records/discover_enum_files.rs"] reason = "Each discovers its own kind of project file with the shared reader; only the call sequence is alike." @@ -3652,10 +3633,6 @@ reason = "Each converts its own input into its own native or Python value; only paths = ["crates/sqlbuild-python-project/src/compiled_views/main/compiled_models/declared_rows.rs", "crates/sqlbuild-python-project/src/compiled_views/main/compiled_models/dep_rows.rs"] reason = "Each converts its own input into its own native or Python value; only the conversion shape is alike." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-front/src/state_rows/_helpers/event_rows/freshness.rs", "crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/relation_targets.rs"] -reason = "Each builds its own error class's exception from a message; sharing one exception constructor across the binding crates is a separate change." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-project/src/planner_phases/main/sorted_names.rs", "crates/sqlbuild-python-planner/src/planner_warehouse/_helpers/sources/source_columns.rs"] reason = "Each converts its own input into its own native or Python value; only the conversion shape is alike." @@ -3800,10 +3777,6 @@ reason = "Each positional record converts its own fields; models.rs holds only r paths = ["crates/sqlbuild-python-compile/src/project_assembly/main/model_syntax_checks.rs", "crates/sqlbuild-python-front/src/cursor/_helpers/intervals.rs", "crates/sqlbuild-python-front/src/scopes/_helpers/index/scope_lookup.rs", "crates/sqlbuild-python-project/src/planner_selection/_helpers/unit_tests.rs"] reason = "Each builds its own tuple from its own items; only the collect-into-tuple shape is alike." -[[dupes.allowlist]] -paths = ["crates/sqlbuild-python-compile/src/compile_driver/_helpers/setup/targets.rs", "crates/sqlbuild-python-planner/src/lifecycle_events/_helpers/envelopes.rs", "crates/sqlbuild-python/src/bindings/_helpers/execution_history/conversion.rs", "crates/sqlbuild-python/src/bindings/_helpers/output_capture/records.rs"] -reason = "Each reads its own optional text value; only the downcast-to-string shape is alike." - [[dupes.allowlist]] paths = ["crates/sqlbuild-python-compile/src/lineage/models.rs", "crates/sqlbuild-python-front/src/contracts/main/matching_dynamic_families.rs", "crates/sqlbuild-python/src/bindings/_helpers/contract_command/command.rs"] reason = "Each builds its own tuple from its own items; only the collect-into-tuple shape is alike." @@ -3859,3 +3832,11 @@ reason = "Each decides which errors its own loader treats as project input error [[dupes.allowlist]] paths = ["crates/sqlbuild-rules/src/python_rules/_helpers/units/orchestration.rs", "crates/sqlbuild-rules/src/python_rules/_helpers/units/providers.rs"] reason = "Each is one rule family's entry point: return early when no rule is selected, then run its own layout, module and import checks. Parsing, project modules and import resolution share files_naming, project_modules and rejected_import_faults." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/manifest.rs"] +reason = "Each builds its own dbt manifest record type with that type's fields; only the record-building shape is alike." + +[[dupes.allowlist]] +paths = ["crates/sqlbuild-python/src/bindings/_helpers/dbt_interop/cli.rs"] +reason = "Each is its own Python entry point with its own keyword contract and dbt command shape; both end in the shared argv builder."