Skip to content

Commit bb4a78f

Browse files
authored
Allow to see the context of a Unsupported query for a subscription (#621)
1 parent 6efcdfa commit bb4a78f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

crates/core/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use hex::FromHexError;
77
use thiserror::Error;
88

99
use crate::client::ClientActorId;
10+
use crate::sql::query_debug_info::QueryDebugInfo;
1011
use spacetimedb_lib::buffer::DecodeError;
1112
use spacetimedb_lib::{PrimaryKey, ProductValue};
1213
use spacetimedb_primitives::{ColId, IndexId, TableId};
@@ -92,6 +93,8 @@ pub enum SubscriptionError {
9293
Empty,
9394
#[error("Queries with side effects not allowed: {0:?}")]
9495
SideEffect(Crud),
96+
#[error("Unsupported query on subscription: {0:?}")]
97+
Unsupported(QueryDebugInfo),
9598
}
9699

97100
#[derive(Error, Debug)]

crates/core/src/subscription/query.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,10 @@ mod tests {
10941094
"SELECT * FROM lhs JOIN rhs ON lhs.id = rhs.id WHERE lhs.x < 10",
10951095
];
10961096
for join in joins {
1097-
assert!(compile_read_only_query(&db, &tx, &auth, join).is_err(), "{join}");
1097+
match compile_read_only_query(&db, &tx, &auth, join) {
1098+
Err(DBError::Subscription(SubscriptionError::Unsupported(_))) => (),
1099+
x => panic!("Unexpected: {x:?}"),
1100+
}
10981101
}
10991102

11001103
Ok(())

crates/core/src/subscription/subscription.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::time::Instant;
3333

3434
use crate::db::datastore::locking_tx_datastore::MutTxId;
3535
use crate::db::db_metrics::{DB_METRICS, MAX_QUERY_CPU_TIME};
36-
use crate::error::DBError;
36+
use crate::error::{DBError, SubscriptionError};
3737
use crate::execution_context::{ExecutionContext, WorkloadType};
3838
use crate::sql::query_debug_info::QueryDebugInfo;
3939
use crate::subscription::query::{run_query, OP_TYPE_FIELD_NAME};
@@ -94,7 +94,7 @@ pub struct SupportedQuery {
9494

9595
impl SupportedQuery {
9696
pub fn new(expr: QueryExpr, info: QueryDebugInfo) -> Result<Self, DBError> {
97-
let kind = query::classify(&expr).context("Unsupported query expression")?;
97+
let kind = query::classify(&expr).ok_or_else(|| SubscriptionError::Unsupported(info.clone()))?;
9898
Ok(Self { kind, expr, info })
9999
}
100100

@@ -128,7 +128,7 @@ impl AsRef<QueryExpr> for SupportedQuery {
128128
}
129129

130130
/// A set of [supported][`SupportedQuery`] [`QueryExpr`]s.
131-
#[derive(Deref, DerefMut, PartialEq, From, IntoIterator)]
131+
#[derive(Debug, Deref, DerefMut, PartialEq, From, IntoIterator)]
132132
pub struct QuerySet(BTreeSet<SupportedQuery>);
133133

134134
impl From<SupportedQuery> for QuerySet {

0 commit comments

Comments
 (0)