Skip to content

Commit ba3c1a9

Browse files
committed
all: Rename 'constraint violation' to 'internal error'
1 parent 8a4cc05 commit ba3c1a9

27 files changed

+164
-185
lines changed

graph/src/components/server/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl From<QueryError> for ServerError {
2828
impl From<StoreError> for ServerError {
2929
fn from(e: StoreError) -> Self {
3030
match e {
31-
StoreError::ConstraintViolation(s) => ServerError::InternalError(s),
31+
StoreError::InternalError(s) => ServerError::InternalError(s),
3232
_ => ServerError::ClientError(e.to_string()),
3333
}
3434
}

graph/src/components/store/err.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub enum StoreError {
3636
/// An internal error where we expected the application logic to enforce
3737
/// some constraint, e.g., that subgraph names are unique, but found that
3838
/// constraint to not hold
39-
#[error("internal constraint violated: {0}")]
40-
ConstraintViolation(String),
39+
#[error("internal error: {0}")]
40+
InternalError(String),
4141
#[error("deployment not found: {0}")]
4242
DeploymentNotFound(String),
4343
#[error("shard not found: {0} (this usually indicates a misconfiguration)")]
@@ -72,14 +72,14 @@ pub enum StoreError {
7272
StatementTimeout,
7373
}
7474

75-
// Convenience to report a constraint violation
75+
// Convenience to report an internal error
7676
#[macro_export]
77-
macro_rules! constraint_violation {
77+
macro_rules! internal_error {
7878
($msg:expr) => {{
79-
$crate::prelude::StoreError::ConstraintViolation(format!("{}", $msg))
79+
$crate::prelude::StoreError::InternalError(format!("{}", $msg))
8080
}};
8181
($fmt:expr, $($arg:tt)*) => {{
82-
$crate::prelude::StoreError::ConstraintViolation(format!($fmt, $($arg)*))
82+
$crate::prelude::StoreError::InternalError(format!($fmt, $($arg)*))
8383
}}
8484
}
8585

@@ -106,7 +106,7 @@ impl Clone for StoreError {
106106
Self::DuplicateBlockProcessing(arg0, arg1) => {
107107
Self::DuplicateBlockProcessing(arg0.clone(), arg1.clone())
108108
}
109-
Self::ConstraintViolation(arg0) => Self::ConstraintViolation(arg0.clone()),
109+
Self::InternalError(arg0) => Self::InternalError(arg0.clone()),
110110
Self::DeploymentNotFound(arg0) => Self::DeploymentNotFound(arg0.clone()),
111111
Self::UnknownShard(arg0) => Self::UnknownShard(arg0.clone()),
112112
Self::FulltextSearchNonDeterministic => Self::FulltextSearchNonDeterministic,
@@ -181,7 +181,7 @@ impl StoreError {
181181
| QueryExecutionError(_)
182182
| ChildFilterNestingNotSupportedError(_, _)
183183
| DuplicateBlockProcessing(_, _)
184-
| ConstraintViolation(_)
184+
| InternalError(_)
185185
| DeploymentNotFound(_)
186186
| UnknownShard(_)
187187
| FulltextSearchNonDeterministic

graph/src/components/store/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use std::time::Duration;
2626
use crate::blockchain::{Block, BlockHash, BlockPtr};
2727
use crate::cheap_clone::CheapClone;
2828
use crate::components::store::write::EntityModification;
29-
use crate::constraint_violation;
3029
use crate::data::store::scalar::Bytes;
3130
use crate::data::store::{Id, IdList, Value};
3231
use crate::data::value::Word;
3332
use crate::data_source::CausalityRegion;
3433
use crate::derive::CheapClone;
3534
use crate::env::ENV_VARS;
35+
use crate::internal_error;
3636
use crate::prelude::{s, Attribute, DeploymentHash, ValueType};
3737
use crate::schema::{ast as sast, EntityKey, EntityType, InputSchema};
3838
use crate::util::stats::MovingStats;
@@ -1000,17 +1000,17 @@ impl PruneRequest {
10001000
let rebuild_threshold = ENV_VARS.store.rebuild_threshold;
10011001
let delete_threshold = ENV_VARS.store.delete_threshold;
10021002
if rebuild_threshold < 0.0 || rebuild_threshold > 1.0 {
1003-
return Err(constraint_violation!(
1003+
return Err(internal_error!(
10041004
"the copy threshold must be between 0 and 1 but is {rebuild_threshold}"
10051005
));
10061006
}
10071007
if delete_threshold < 0.0 || delete_threshold > 1.0 {
1008-
return Err(constraint_violation!(
1008+
return Err(internal_error!(
10091009
"the delete threshold must be between 0 and 1 but is {delete_threshold}"
10101010
));
10111011
}
10121012
if history_blocks <= reorg_threshold {
1013-
return Err(constraint_violation!(
1013+
return Err(internal_error!(
10141014
"the deployment {} needs to keep at least {} blocks \
10151015
of history and can't be pruned to only {} blocks of history",
10161016
deployment,
@@ -1019,7 +1019,7 @@ impl PruneRequest {
10191019
));
10201020
}
10211021
if first_block >= latest_block {
1022-
return Err(constraint_violation!(
1022+
return Err(internal_error!(
10231023
"the earliest block {} must be before the latest block {}",
10241024
first_block,
10251025
latest_block

graph/src/components/store/write.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use crate::{
55
blockchain::{block_stream::FirehoseCursor, BlockPtr, BlockTime},
66
cheap_clone::CheapClone,
77
components::subgraph::Entity,
8-
constraint_violation,
98
data::{store::Id, subgraph::schema::SubgraphError},
109
data_source::CausalityRegion,
1110
derive::CacheWeight,
11+
internal_error,
1212
util::cache_weight::CacheWeight,
1313
};
1414

@@ -182,7 +182,7 @@ impl EntityModification {
182182
match self {
183183
Insert { end, .. } | Overwrite { end, .. } => {
184184
if end.is_some() {
185-
return Err(constraint_violation!(
185+
return Err(internal_error!(
186186
"can not clamp {:?} to block {}",
187187
self,
188188
block
@@ -191,7 +191,7 @@ impl EntityModification {
191191
*end = Some(block);
192192
}
193193
Remove { .. } => {
194-
return Err(constraint_violation!(
194+
return Err(internal_error!(
195195
"can not clamp block range for removal of {:?} to {}",
196196
self,
197197
block
@@ -219,7 +219,7 @@ impl EntityModification {
219219
end,
220220
}),
221221
Remove { key, .. } => {
222-
return Err(constraint_violation!(
222+
return Err(internal_error!(
223223
"a remove for {}[{}] can not be converted into an insert",
224224
entity_type,
225225
key.entity_id
@@ -330,7 +330,7 @@ impl RowGroup {
330330
if !is_forward {
331331
// unwrap: we only get here when `last()` is `Some`
332332
let last_block = self.rows.last().map(|emod| emod.block()).unwrap();
333-
return Err(constraint_violation!(
333+
return Err(internal_error!(
334334
"we already have a modification for block {}, can not append {:?}",
335335
last_block,
336336
emod
@@ -412,7 +412,7 @@ impl RowGroup {
412412
self.rows.push(row);
413413
}
414414
EntityModification::Overwrite { .. } | EntityModification::Remove { .. } => {
415-
return Err(constraint_violation!(
415+
return Err(internal_error!(
416416
"immutable entity type {} only allows inserts, not {:?}",
417417
self.entity_type,
418418
row
@@ -426,7 +426,7 @@ impl RowGroup {
426426
use EntityModification::*;
427427

428428
if row.block() <= prev_row.block() {
429-
return Err(constraint_violation!(
429+
return Err(internal_error!(
430430
"can not append operations that go backwards from {:?} to {:?}",
431431
prev_row,
432432
row
@@ -444,7 +444,7 @@ impl RowGroup {
444444
Insert { end: Some(_), .. } | Overwrite { end: Some(_), .. },
445445
Overwrite { .. } | Remove { .. },
446446
) => {
447-
return Err(constraint_violation!(
447+
return Err(internal_error!(
448448
"impossible combination of entity operations: {:?} and then {:?}",
449449
prev_row,
450450
row
@@ -481,7 +481,7 @@ impl RowGroup {
481481

482482
fn append(&mut self, group: RowGroup) -> Result<(), StoreError> {
483483
if self.entity_type != group.entity_type {
484-
return Err(constraint_violation!(
484+
return Err(internal_error!(
485485
"Can not append a row group for {} to a row group for {}",
486486
group.entity_type,
487487
self.entity_type
@@ -710,7 +710,7 @@ impl Batch {
710710

711711
fn append_inner(&mut self, mut batch: Batch) -> Result<(), StoreError> {
712712
if batch.block_ptr.number <= self.block_ptr.number {
713-
return Err(constraint_violation!("Batches must go forward. Can't append a batch with block pointer {} to one with block pointer {}", batch.block_ptr, self.block_ptr));
713+
return Err(internal_error!("Batches must go forward. Can't append a batch with block pointer {} to one with block pointer {}", batch.block_ptr, self.block_ptr));
714714
}
715715

716716
self.block_ptr = batch.block_ptr;

graph/src/data/query/error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub enum QueryExecutionError {
7474
DeploymentNotFound(String),
7575
IdMissing,
7676
IdNotString,
77-
ConstraintViolation(String),
77+
InternalError(String),
7878
}
7979

8080
impl QueryExecutionError {
@@ -132,7 +132,7 @@ impl QueryExecutionError {
132132
| DeploymentNotFound(_)
133133
| IdMissing
134134
| IdNotString
135-
| ConstraintViolation(_) => false,
135+
| InternalError(_) => false,
136136
}
137137
}
138138
}
@@ -274,7 +274,7 @@ impl fmt::Display for QueryExecutionError {
274274
DeploymentNotFound(id_or_name) => write!(f, "deployment `{}` does not exist", id_or_name),
275275
IdMissing => write!(f, "entity is missing an `id` attribute"),
276276
IdNotString => write!(f, "entity `id` attribute is not a string"),
277-
ConstraintViolation(msg) => write!(f, "internal constraint violated: {}", msg),
277+
InternalError(msg) => write!(f, "internal error: {}", msg),
278278
}
279279
}
280280
}
@@ -306,7 +306,7 @@ impl From<StoreError> for QueryExecutionError {
306306
StoreError::ChildFilterNestingNotSupportedError(attr, filter) => {
307307
QueryExecutionError::ChildFilterNestingNotSupportedError(attr, filter)
308308
}
309-
StoreError::ConstraintViolation(msg) => QueryExecutionError::ConstraintViolation(msg),
309+
StoreError::InternalError(msg) => QueryExecutionError::InternalError(msg),
310310
_ => QueryExecutionError::StoreError(CloneableAnyhowError(Arc::new(e.into()))),
311311
}
312312
}

graph/src/data/store/id.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use crate::{
2020

2121
use crate::{
2222
components::store::StoreError,
23-
constraint_violation,
2423
data::value::Word,
2524
derive::CacheWeight,
25+
internal_error,
2626
prelude::QueryExecutionError,
2727
runtime::gas::{Gas, GasSizeOf},
2828
};
@@ -367,7 +367,7 @@ impl IdList {
367367
ids.push(id);
368368
Ok(ids)
369369
}
370-
_ => Err(constraint_violation!(
370+
_ => Err(internal_error!(
371371
"expected string id, got {}: {}",
372372
id.id_type(),
373373
id,
@@ -381,7 +381,7 @@ impl IdList {
381381
ids.push(id);
382382
Ok(ids)
383383
}
384-
_ => Err(constraint_violation!(
384+
_ => Err(internal_error!(
385385
"expected bytes id, got {}: {}",
386386
id.id_type(),
387387
id,
@@ -395,7 +395,7 @@ impl IdList {
395395
ids.push(id);
396396
Ok(ids)
397397
}
398-
_ => Err(constraint_violation!(
398+
_ => Err(internal_error!(
399399
"expected int8 id, got {}: {}",
400400
id.id_type(),
401401
id,
@@ -423,7 +423,7 @@ impl IdList {
423423
ids.push(Word::from(id));
424424
Ok(ids)
425425
}
426-
_ => Err(constraint_violation!(
426+
_ => Err(internal_error!(
427427
"expected string id, got {}: 0x{}",
428428
id.id_type(),
429429
id,
@@ -438,7 +438,7 @@ impl IdList {
438438
ids.push(scalar::Bytes::from(id));
439439
Ok(ids)
440440
}
441-
_ => Err(constraint_violation!(
441+
_ => Err(internal_error!(
442442
"expected bytes id, got {}: {}",
443443
id.id_type(),
444444
id,
@@ -452,7 +452,7 @@ impl IdList {
452452
ids.push(id);
453453
Ok(ids)
454454
}
455-
_ => Err(constraint_violation!(
455+
_ => Err(internal_error!(
456456
"expected int8 id, got {}: {}",
457457
id.id_type(),
458458
id,
@@ -533,7 +533,7 @@ impl IdList {
533533
ids.push(id);
534534
Ok(())
535535
}
536-
(list, id) => Err(constraint_violation!(
536+
(list, id) => Err(internal_error!(
537537
"expected id of type {}, but got {}[{}]",
538538
list.id_type(),
539539
id.id_type(),

graph/src/util/ogive.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::RangeInclusive;
22

3-
use crate::{constraint_violation, prelude::StoreError};
3+
use crate::{internal_error, prelude::StoreError};
44

55
/// A helper to deal with cumulative histograms, also known as ogives. This
66
/// implementation is restricted to histograms where each bin has the same
@@ -37,9 +37,7 @@ impl Ogive {
3737
/// and deduplicated, i.e., they don't have to be in ascending order.
3838
pub fn from_equi_histogram(mut points: Vec<i64>, total: usize) -> Result<Self, StoreError> {
3939
if points.is_empty() {
40-
return Err(constraint_violation!(
41-
"histogram must have at least one point"
42-
));
40+
return Err(internal_error!("histogram must have at least one point"));
4341
}
4442

4543
points.sort_unstable();
@@ -124,7 +122,7 @@ impl Ogive {
124122
fn inverse(&self, value: i64) -> Result<i64, StoreError> {
125123
let value = value as f64;
126124
if value < 0.0 {
127-
return Err(constraint_violation!("value {} can not be negative", value));
125+
return Err(internal_error!("value {} can not be negative", value));
128126
}
129127
let idx = (value / self.bin_size) as usize;
130128
if idx >= self.points.len() - 1 {
@@ -138,7 +136,7 @@ impl Ogive {
138136

139137
fn check_in_range(&self, point: i64) -> Result<(), StoreError> {
140138
if !self.range.contains(&point) {
141-
return Err(constraint_violation!(
139+
return Err(internal_error!(
142140
"point {} is outside of the range [{}, {}]",
143141
point,
144142
self.range.start(),

graphql/src/store/prefetch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'a> Loader<'a> {
632632
let object_type = input_schema
633633
.object_or_aggregation(&object_type.name, parent_interval)
634634
.ok_or_else(|| {
635-
vec![QueryExecutionError::ConstraintViolation(format!(
635+
vec![QueryExecutionError::InternalError(format!(
636636
"the type `{}`(interval {}) is not an object type",
637637
object_type.name,
638638
parent_interval

graphql/src/store/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl Resolver for StoreResolver {
327327
None => {
328328
let child0_id = child_id(&children[0]);
329329
let child1_id = child_id(&children[1]);
330-
QueryExecutionError::ConstraintViolation(format!(
330+
QueryExecutionError::InternalError(format!(
331331
"expected only one child for {}.{} but got {}. One child has id {}, another has id {}",
332332
object_type.name(), field.name,
333333
children.len(), child0_id, child1_id

0 commit comments

Comments
 (0)