Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-3919: Return error instead of panic in SelectCompiler #6163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/hash-graph/src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub async fn server(args: ServerArgs) -> Result<(), Report<GraphError>> {
let mut zanzibar_client = ZanzibarClient::new(spicedb_client);
zanzibar_client.seed().await.change_context(GraphError)?;

let temporal_client_fn = async |host: Option<String>, port: u16| {
let temporal_client_fn = |host: Option<String>, port: u16| async move {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: async closures are unstable, we can use the stable way

if let Some(host) = host {
TemporalClientConfig::new(
Url::from_str(&format!("{host}:{port}")).change_context(GraphError)?,
Expand Down
2 changes: 1 addition & 1 deletion libs/@local/graph/api/src/rest/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl<'q, 's, 'p: 'q> From<GetEntitiesRequest<'q, 's, 'p>> for GetEntitiesParams<
#[tracing::instrument(
level = "info",
skip_all,
fields(actor=%actor_id, %request)
fields(actor=%actor_id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by: This would include the embedding in the log, which is quite large.

)]
async fn get_entities<S, A>(
AuthenticatedUserHeader(actor_id): AuthenticatedUserHeader,
Expand Down
1 change: 1 addition & 0 deletions libs/@local/graph/postgres-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async-scoped = { workspace = true, features = ["use-tokio"] }
bytes = { workspace = true }
clap = { workspace = true, optional = true, features = ["derive", "env"] }
derive-where = { workspace = true }
derive_more = { workspace = true }
dotenv-flow = { workspace = true }
futures = { workspace = true }
postgres-types = { workspace = true, features = ["derive", "with-serde_json-1"] }
Expand Down
20 changes: 11 additions & 9 deletions libs/@local/graph/postgres-store/src/store/postgres/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ where
compiler.set_limit(limit);
}

compiler.add_filter(filter);

let cursor_indices = sorting.compile(
&mut compiler,
cursor_parameters.as_ref(),
temporal_axes.expect("To use a cursor, temporal axes has to be specified"),
);
compiler.add_filter(filter).change_context(QueryError)?;

let cursor_indices = sorting
.compile(
&mut compiler,
cursor_parameters.as_ref(),
temporal_axes.expect("To use a cursor, temporal axes has to be specified"),
)
.change_context(QueryError)?;

let record_artifacts = R::parameters();
let record_indices = R::compile(&mut compiler, &record_artifacts);
Expand Down Expand Up @@ -145,7 +147,7 @@ where
let record_artifacts = R::parameters();
let record_indices = R::compile(&mut compiler, &record_artifacts);

compiler.add_filter(filter);
compiler.add_filter(filter).change_context(QueryError)?;
let (statement, parameters) = compiler.compile();

Ok(self
Expand All @@ -170,7 +172,7 @@ where
let record_artifacts = R::parameters();
let record_indices = R::compile(&mut compiler, &record_artifacts);

compiler.add_filter(filter);
compiler.add_filter(filter).change_context(QueryError)?;
let (statement, parameters) = compiler.compile();

let rows = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,9 @@ where
)
});

compiler.add_filter(&params.filter);
compiler
.add_filter(&params.filter)
.change_context(QueryError)?;

let (statement, parameters) = compiler.compile();

Expand Down Expand Up @@ -620,7 +622,6 @@ where
.count();
let type_ids = type_ids.map(HashMap::from);

#[expect(clippy::if_then_some_else_none)]
let type_titles = if params.include_type_titles {
let type_uuids = type_ids
.as_ref()
Expand All @@ -643,7 +644,9 @@ where
},
ParameterList::EntityTypeIds(&type_uuids),
);
type_compiler.add_filter(&filter);
type_compiler
.add_filter(&filter)
.change_context(QueryError)?;

let (statement, parameters) = type_compiler.compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ where
compiler.add_selection_path(&EntityTypeQueryPath::EditionProvenance(None))
});

compiler.add_filter(&params.filter);
compiler
.add_filter(&params.filter)
.change_context(QueryError)?;

let (statement, parameters) = compiler.compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::store::{
postgres::{
AsClient as _, PostgresStore,
crud::QueryRecordDecode,
query::{Distinctness, PostgresSorting, SelectCompiler},
query::{Distinctness, PostgresSorting, SelectCompiler, SelectCompilerError},
},
};

Expand Down Expand Up @@ -153,29 +153,29 @@ macro_rules! impl_ontology_cursor {
compiler: &mut SelectCompiler<'p, 'q, $ty>,
parameters: Option<&'p Self::CompilationParameters>,
_: &QueryTemporalAxes,
) -> Self::Indices {
) -> Result<Self::Indices, Report<SelectCompilerError>> {
if let Some(parameters) = parameters {
let base_url_expression = compiler.compile_parameter(&parameters.base_url).0;
let version_expression = compiler.compile_parameter(&parameters.version).0;

VersionedUrlIndices {
Ok(VersionedUrlIndices {
base_url: compiler.add_cursor_selection(
&<$query_path>::BaseUrl,
identity,
Some(base_url_expression),
Ordering::Ascending,
None,
),
)?,
version: compiler.add_cursor_selection(
&<$query_path>::Version,
identity,
Some(version_expression),
Ordering::Descending,
None,
),
}
)?,
})
} else {
VersionedUrlIndices {
Ok(VersionedUrlIndices {
base_url: compiler.add_distinct_selection_with_ordering(
&<$query_path>::BaseUrl,
Distinctness::Distinct,
Expand All @@ -186,7 +186,7 @@ macro_rules! impl_ontology_cursor {
Distinctness::Distinct,
Some((Ordering::Descending, None)),
),
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<C: AsClient, A: Send + Sync> PostgresStore<C, A> {
let closed_schema_index =
compiler.add_selection_path(&EntityTypeQueryPath::ClosedSchema(None));

compiler.add_filter(filter);
compiler.add_filter(filter).change_context(QueryError)?;
let (statement, parameters) = compiler.compile();

Ok(self
Expand Down
Loading
Loading