use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use crate::error::{Neo4jStoreError, Result};
use crate::storage_interface::{
SchemaConstraintDescriptor, SchemaDescriptor, SchemaEntityType, SchemaIndexDescriptor,
SchemaMetadata,
};
use crate::value::{Properties, Value};
use super::page::{PageLayout, RecordReader};
use super::Neo4jStoreFormat;
const SCHEMA_STORE: &str = "neostore.schemastore.db";
const SCHEMA_RECORD_SIZE: usize = 8;
const IN_USE: u8 = 0x01;
const HAS_PROPERTY: u8 = 0x02;
const PROPERTY_REFERENCE_MASK: u64 = 0x00ff_ffff_ffff_ffff;
const PREFIX: &str = "__org.neo4j.SchemaRule.";
pub(super) fn load(
database_directory: &Path,
format: Neo4jStoreFormat,
labels: &BTreeMap<u32, String>,
relationship_types: &BTreeMap<u32, String>,
property_keys: &BTreeMap<u32, String>,
) -> Result<SchemaMetadata> {
let path = database_directory.join(SCHEMA_STORE);
let layout = PageLayout::new(&path, format, SCHEMA_RECORD_SIZE)?;
let mut reader = RecordReader::open(&path, "schema", layout)?;
let mut heads = Vec::new();
for record_id in 0..reader.record_count() {
let bytes = reader.read(record_id)?;
if bytes[0] & IN_USE == 0 {
continue;
}
if bytes[0] & HAS_PROPERTY == 0 {
return Err(invalid_rule(
&reader,
record_id,
"active schema rule has no property chain",
));
}
let head = u64::from_be_bytes(bytes.try_into().expect("schema record size"))
& PROPERTY_REFERENCE_MASK;
heads.push((record_id, head));
}
let maps =
super::property::load_schema_properties(database_directory, format, property_keys, &heads)?;
let mut metadata = SchemaMetadata::default();
for (record_id, properties) in maps {
parse_rule(
record_id,
&properties,
labels,
relationship_types,
property_keys,
&mut metadata,
)
.map_err(|message| invalid_rule(&reader, record_id, message))?;
}
Ok(metadata)
}
fn parse_rule(
id: u64,
properties: &Properties,
labels: &BTreeMap<u32, String>,
relationship_types: &BTreeMap<u32, String>,
property_keys: &BTreeMap<u32, String>,
metadata: &mut SchemaMetadata,
) -> std::result::Result<(), String> {
let schema = parse_schema(properties, labels, relationship_types, property_keys)?;
let name = required_string(properties, "name")?.to_owned();
match required_string(properties, "schemaRuleType")? {
"INDEX" => {
let rule_type = required_string(properties, "indexRuleType")?;
let unique = match rule_type {
"NON_UNIQUE" => false,
"UNIQUE" => true,
value => return Err(format!("unknown index rule type `{value}`")),
};
let index_type = parse_index_type(required_string(properties, "indexType")?)?;
let provider = format!(
"{}-{}",
required_string(properties, "indexProviderName")?,
required_string(properties, "indexProviderVersion")?
);
metadata.indexes.push(SchemaIndexDescriptor {
id,
name,
schema,
index_type,
provider,
unique,
owning_constraint: optional_u64(properties, "owningConstraint")?,
});
}
"CONSTRAINT" => {
let constraint_type = required_string(properties, "constraintRuleType")?.to_owned();
if !matches!(
constraint_type.as_str(),
"UNIQUE"
| "EXISTS"
| "UNIQUE_EXISTS"
| "PROPERTY_TYPE"
| "RELATIONSHIP_ENDPOINT_LABEL"
| "NODE_LABEL_EXISTENCE"
) {
return Err(format!("unknown constraint rule type `{constraint_type}`"));
}
match constraint_type.as_str() {
"RELATIONSHIP_ENDPOINT_LABEL"
if schema.entity_type != SchemaEntityType::Relationship
|| schema.matching_type != "SINGLE_ENTITY_TOKEN" =>
{
return Err(
"relationship endpoint label constraint requires a single relationship-type schema"
.to_owned(),
);
}
"NODE_LABEL_EXISTENCE"
if schema.entity_type != SchemaEntityType::Node
|| schema.matching_type != "SINGLE_ENTITY_TOKEN" =>
{
return Err(
"node label existence constraint requires a single-label schema".to_owned(),
);
}
_ => {}
}
let graph_type_dependence = optional_string(properties, "graphTypeDependence")?
.unwrap_or(
if matches!(constraint_type.as_str(), "UNIQUE" | "UNIQUE_EXISTS") {
"UNDESIGNATED"
} else {
"INDEPENDENT"
},
)
.to_owned();
if !matches!(
graph_type_dependence.as_str(),
"UNDESIGNATED" | "INDEPENDENT" | "DEPENDENT"
) {
return Err(format!(
"unknown graph type dependence `{graph_type_dependence}`"
));
}
if matches!(constraint_type.as_str(), "UNIQUE" | "UNIQUE_EXISTS")
&& graph_type_dependence != "UNDESIGNATED"
{
return Err(format!(
"graph type dependence `{graph_type_dependence}` is incompatible with constraint type `{constraint_type}`"
));
}
let index_type = if matches!(constraint_type.as_str(), "UNIQUE" | "UNIQUE_EXISTS") {
Some(parse_index_type(required_string(properties, "indexType")?)?)
} else {
None
};
let property_types = if constraint_type == "PROPERTY_TYPE" {
let serialized = required_string_list(properties, "propertyType")?;
if serialized.is_empty() {
return Err("property type constraint has no allowed property types".to_owned());
}
serialized
.iter()
.map(|value| property_type_user_description(value))
.collect::<std::result::Result<Vec<_>, _>>()?
} else {
Vec::new()
};
let endpoint_type = if constraint_type == "RELATIONSHIP_ENDPOINT_LABEL" {
let value = required_string(properties, "endpointType")?;
if !matches!(value, "START" | "END") {
return Err(format!("unknown endpoint type `{value}`"));
}
Some(value.to_owned())
} else {
None
};
let endpoint_label = optional_u64(properties, "endpointLabelId")?
.map(|value| resolve_token(labels, value, "label"))
.transpose()?;
let required_label = optional_u64(properties, "requiredLabelId")?
.map(|value| resolve_token(labels, value, "label"))
.transpose()?;
if constraint_type == "RELATIONSHIP_ENDPOINT_LABEL" && endpoint_label.is_none() {
return Err("schema property `endpointLabelId` is missing".to_owned());
}
if constraint_type == "NODE_LABEL_EXISTENCE" && required_label.is_none() {
return Err("schema property `requiredLabelId` is missing".to_owned());
}
metadata.constraints.push(SchemaConstraintDescriptor {
id,
name,
schema,
constraint_type,
graph_type_dependence,
index_type,
owned_index: optional_u64(properties, "ownedIndex")?,
property_types,
endpoint_type,
endpoint_label,
required_label,
});
}
value => return Err(format!("unknown schema rule type `{value}`")),
}
Ok(())
}
fn parse_schema(
properties: &Properties,
labels: &BTreeMap<u32, String>,
relationship_types: &BTreeMap<u32, String>,
property_keys: &BTreeMap<u32, String>,
) -> std::result::Result<SchemaDescriptor, String> {
let entity_type = match required_string(properties, "schemaEntityType")? {
"NODE" => SchemaEntityType::Node,
"RELATIONSHIP" => SchemaEntityType::Relationship,
value => return Err(format!("unknown schema entity type `{value}`")),
};
let matching_type = required_string(properties, "schemaPropertySchemaType")?.to_owned();
if !matches!(
matching_type.as_str(),
"COMPLETE_ALL_TOKENS" | "PARTIAL_ANY_TOKEN" | "ENTITY_TOKENS" | "SINGLE_ENTITY_TOKEN"
) {
return Err(format!("unknown schema matching type `{matching_type}`"));
}
let entity_catalog = match entity_type {
SchemaEntityType::Node => labels,
SchemaEntityType::Relationship => relationship_types,
};
let entity_ids = required_ids(properties, "schemaEntityIds")?;
let property_ids = required_ids(properties, "schemaPropertyIds")?;
match matching_type.as_str() {
"COMPLETE_ALL_TOKENS" if entity_ids.len() != 1 || property_ids.is_empty() => {
return Err(
"complete property schema requires exactly one entity token and at least one property key"
.to_owned(),
);
}
"PARTIAL_ANY_TOKEN" if entity_ids.is_empty() || property_ids.is_empty() => {
return Err(
"partial property schema requires at least one entity token and property key"
.to_owned(),
);
}
"ENTITY_TOKENS" if !entity_ids.is_empty() || !property_ids.is_empty() => {
return Err("entity-token schema must not contain entity or property IDs".to_owned());
}
"SINGLE_ENTITY_TOKEN" if entity_ids.len() != 1 || !property_ids.is_empty() => {
return Err(
"single-entity-token schema requires exactly one entity token and no property keys"
.to_owned(),
);
}
_ => {}
}
let entity_tokens = entity_ids
.into_iter()
.map(|id| resolve_token(entity_catalog, id, "entity"))
.collect::<std::result::Result<Vec<_>, _>>()?;
let property_keys = property_ids
.into_iter()
.map(|id| resolve_token(property_keys, id, "property key"))
.collect::<std::result::Result<Vec<_>, _>>()?;
Ok(SchemaDescriptor {
entity_type,
entity_tokens,
property_keys,
matching_type,
})
}
fn key(name: &str) -> String {
format!("{PREFIX}{name}")
}
fn required_string<'a>(
properties: &'a Properties,
name: &str,
) -> std::result::Result<&'a str, String> {
match properties.get(&key(name)) {
Some(Value::String(value)) => Ok(value),
Some(_) => Err(format!("schema property `{name}` has the wrong type")),
None => Err(format!("schema property `{name}` is missing")),
}
}
fn optional_string<'a>(
properties: &'a Properties,
name: &str,
) -> std::result::Result<Option<&'a str>, String> {
match properties.get(&key(name)) {
Some(Value::String(value)) => Ok(Some(value)),
Some(_) => Err(format!("schema property `{name}` has the wrong type")),
None => Ok(None),
}
}
fn required_ids(properties: &Properties, name: &str) -> std::result::Result<Vec<u64>, String> {
match properties.get(&key(name)) {
Some(Value::List(values)) => values
.iter()
.map(|value| match value {
Value::Integer(value) if *value >= 0 => Ok(*value as u64),
_ => Err(format!(
"schema property `{name}` contains a non-integer token ID"
)),
})
.collect(),
Some(_) => Err(format!("schema property `{name}` has the wrong type")),
None => Err(format!("schema property `{name}` is missing")),
}
}
fn optional_u64(properties: &Properties, name: &str) -> std::result::Result<Option<u64>, String> {
match properties.get(&key(name)) {
Some(Value::Integer(value)) if *value >= 0 => Ok(Some(*value as u64)),
Some(_) => Err(format!("schema property `{name}` has the wrong type")),
None => Ok(None),
}
}
fn required_string_list(
properties: &Properties,
name: &str,
) -> std::result::Result<Vec<String>, String> {
match properties.get(&key(name)) {
Some(Value::List(values)) => values
.iter()
.map(|value| match value {
Value::String(value) => Ok(value.clone()),
_ => Err(format!(
"schema property `{name}` contains a non-string value"
)),
})
.collect(),
Some(_) => Err(format!("schema property `{name}` has the wrong type")),
None => Err(format!("schema property `{name}` is missing")),
}
}
fn parse_index_type(value: &str) -> std::result::Result<String, String> {
if matches!(
value,
"RANGE" | "TEXT" | "POINT" | "FULLTEXT" | "LOOKUP" | "VECTOR"
) {
Ok(value.to_owned())
} else {
Err(format!("unknown index type `{value}`"))
}
}
fn property_type_user_description(value: &str) -> std::result::Result<String, String> {
let description = match value {
"BOOLEAN" | "STRING" | "UUID" | "INTEGER" | "FLOAT" | "DATE" | "DURATION" | "POINT" => {
value.to_owned()
}
"LOCAL_TIME" => "LOCAL TIME".to_owned(),
"ZONED_TIME" => "ZONED TIME".to_owned(),
"LOCAL_DATETIME" => "LOCAL DATETIME".to_owned(),
"ZONED_DATETIME" => "ZONED DATETIME".to_owned(),
value if value.starts_with("LIST_") => {
let inner = property_type_user_description(&value[5..])?;
format!("LIST<{inner} NOT NULL>")
}
value if value.starts_with("VECTOR[") && value.ends_with(']') => {
let body = &value[7..value.len() - 1];
let Some((coordinate, dimensions)) = body.split_once(", dimensions=") else {
return Err(format!("unknown schema value type `{value}`"));
};
let Some(coordinate) = coordinate.strip_prefix("coordinate=") else {
return Err(format!("unknown schema value type `{value}`"));
};
let coordinate = match coordinate {
"INTEGER8" => "INTEGER8 NOT NULL",
"INTEGER16" => "INTEGER16 NOT NULL",
"INTEGER32" => "INTEGER32 NOT NULL",
"INTEGER64" => "INTEGER NOT NULL",
"FLOAT32" => "FLOAT32 NOT NULL",
"FLOAT64" => "FLOAT NOT NULL",
_ => return Err(format!("unknown vector coordinate type `{coordinate}`")),
};
let dimensions = dimensions
.parse::<u16>()
.map_err(|_| format!("invalid vector dimensions `{dimensions}`"))?;
if !(1..=4096).contains(&dimensions) {
return Err(format!(
"vector dimensions {dimensions} are outside 1..=4096"
));
}
format!("VECTOR<{coordinate}>({dimensions})")
}
_ => return Err(format!("unknown schema value type `{value}`")),
};
Ok(description)
}
fn resolve_token(
tokens: &BTreeMap<u32, String>,
id: u64,
kind: &str,
) -> std::result::Result<String, String> {
let id = u32::try_from(id).map_err(|_| format!("{kind} token ID {id} exceeds 32 bits"))?;
tokens
.get(&id)
.cloned()
.ok_or_else(|| format!("unknown {kind} token ID {id}"))
}
fn invalid_rule(reader: &RecordReader, record_id: u64, message: impl Into<String>) -> crate::Error {
Neo4jStoreError::InvalidRecord {
path: PathBuf::from(reader.path()),
record_type: "schema".to_owned(),
record_id,
offset: reader.offset(record_id).unwrap_or(u64::MAX),
context: format!("schema rule {record_id}"),
message: message.into(),
}
.into()
}
pub(super) fn validate_writable(database_directory: &Path, format: Neo4jStoreFormat) -> Result<()> {
let path = database_directory.join(SCHEMA_STORE);
let layout = PageLayout::new(&path, format, SCHEMA_RECORD_SIZE)?;
let mut reader = RecordReader::open(&path, "schema", layout)?;
for record_id in 0..reader.record_count() {
let bytes = reader.read(record_id)?;
if bytes[0] & IN_USE != 0 {
return Err(Neo4jStoreError::UnsupportedWritableStore {
path,
message: format!(
"schema record {record_id} is in use; indexes and constraints are not maintained"
),
}
.into());
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use std::fs;
use super::*;
#[test]
fn accepts_a_schema_store_without_active_rules() {
for format in [
Neo4jStoreFormat::StandardV5_0,
Neo4jStoreFormat::AlignedV5_0,
] {
let directory = tempfile::tempdir().unwrap();
fs::write(
directory.path().join(SCHEMA_STORE),
[[0_u8; SCHEMA_RECORD_SIZE]; 3].concat(),
)
.unwrap();
validate_writable(directory.path(), format).unwrap();
}
}
#[test]
fn rejects_any_active_schema_rule() {
let directory = tempfile::tempdir().unwrap();
let mut records = [[0_u8; SCHEMA_RECORD_SIZE]; 3];
records[2][0] = IN_USE;
fs::write(directory.path().join(SCHEMA_STORE), records.concat()).unwrap();
let error = validate_writable(directory.path(), Neo4jStoreFormat::StandardV5_0)
.expect_err("active schema must prevent writable access");
assert!(matches!(
error,
crate::Error::Neo4jStore(Neo4jStoreError::UnsupportedWritableStore {
message,
..
}) if message.contains("schema record 2")
));
}
fn schema_properties(rule_type: &str) -> Properties {
Properties::from([
(key("schemaRuleType"), Value::String(rule_type.to_owned())),
(key("name"), Value::String("rule_name".to_owned())),
(key("schemaEntityType"), Value::String("NODE".to_owned())),
(
key("schemaPropertySchemaType"),
Value::String("COMPLETE_ALL_TOKENS".to_owned()),
),
(key("schemaEntityIds"), Value::List(vec![Value::Integer(3)])),
(
key("schemaPropertyIds"),
Value::List(vec![Value::Integer(7), Value::Integer(8)]),
),
])
}
#[test]
fn parses_index_and_constraint_rule_maps() {
let labels = BTreeMap::from([(3, "Person".to_owned())]);
let relationships = BTreeMap::new();
let property_keys = BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]);
let mut metadata = SchemaMetadata::default();
let mut index = schema_properties("INDEX");
index.insert(key("indexRuleType"), Value::String("NON_UNIQUE".to_owned()));
index.insert(key("indexType"), Value::String("RANGE".to_owned()));
index.insert(key("indexProviderName"), Value::String("range".to_owned()));
index.insert(key("indexProviderVersion"), Value::String("1.0".to_owned()));
parse_rule(
11,
&index,
&labels,
&relationships,
&property_keys,
&mut metadata,
)
.unwrap();
assert_eq!(metadata.indexes[0].id, 11);
assert_eq!(metadata.indexes[0].schema.entity_tokens, ["Person"]);
assert_eq!(metadata.indexes[0].schema.property_keys, ["first", "last"]);
assert_eq!(metadata.indexes[0].provider, "range-1.0");
let mut constraint = schema_properties("CONSTRAINT");
constraint.insert(
key("constraintRuleType"),
Value::String("UNIQUE_EXISTS".to_owned()),
);
constraint.insert(key("indexType"), Value::String("RANGE".to_owned()));
constraint.insert(key("ownedIndex"), Value::Integer(11));
parse_rule(
12,
&constraint,
&labels,
&relationships,
&property_keys,
&mut metadata,
)
.unwrap();
assert_eq!(metadata.constraints[0].owned_index, Some(11));
assert_eq!(metadata.constraints[0].index_type.as_deref(), Some("RANGE"));
assert_eq!(
metadata.constraints[0].graph_type_dependence,
"UNDESIGNATED"
);
}
#[test]
fn rejects_unknown_schema_rule_values_explicitly() {
let mut properties = schema_properties("FUTURE_RULE");
properties.insert(
key("schemaPropertySchemaType"),
Value::String("COMPLETE_ALL_TOKENS".to_owned()),
);
let error = parse_rule(
1,
&properties,
&BTreeMap::from([(3, "Person".to_owned())]),
&BTreeMap::new(),
&BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]),
&mut SchemaMetadata::default(),
)
.unwrap_err();
assert!(error.contains("unknown schema rule type `FUTURE_RULE`"));
}
#[test]
fn accepts_all_schema_matching_types_and_rejects_unknown_values() {
let labels = BTreeMap::from([(3, "Person".to_owned())]);
let properties = BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]);
for matching_type in [
"COMPLETE_ALL_TOKENS",
"PARTIAL_ANY_TOKEN",
"ENTITY_TOKENS",
"SINGLE_ENTITY_TOKEN",
] {
let mut rule = schema_properties("INDEX");
rule.insert(
key("schemaPropertySchemaType"),
Value::String(matching_type.to_owned()),
);
if matching_type == "ENTITY_TOKENS" {
rule.insert(key("schemaEntityIds"), Value::List(Vec::new()));
rule.insert(key("schemaPropertyIds"), Value::List(Vec::new()));
} else if matching_type == "SINGLE_ENTITY_TOKEN" {
rule.insert(key("schemaPropertyIds"), Value::List(Vec::new()));
}
assert_eq!(
parse_schema(&rule, &labels, &BTreeMap::new(), &properties)
.unwrap()
.matching_type,
matching_type
);
}
let mut rule = schema_properties("INDEX");
rule.insert(
key("schemaPropertySchemaType"),
Value::String("FUTURE_MATCHING".to_owned()),
);
assert!(parse_schema(&rule, &labels, &BTreeMap::new(), &properties)
.unwrap_err()
.contains("unknown schema matching type `FUTURE_MATCHING`"));
}
#[test]
fn validates_constraint_enums_and_required_fields() {
let labels = BTreeMap::from([(3, "Person".to_owned()), (4, "Account".to_owned())]);
let relationships = BTreeMap::from([(3, "OWNS".to_owned())]);
let property_keys = BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]);
let mut dependence = schema_properties("CONSTRAINT");
dependence.insert(
key("constraintRuleType"),
Value::String("EXISTS".to_owned()),
);
dependence.insert(
key("graphTypeDependence"),
Value::String("FUTURE_DEPENDENCE".to_owned()),
);
assert!(parse_rule(
1,
&dependence,
&labels,
&relationships,
&property_keys,
&mut SchemaMetadata::default(),
)
.unwrap_err()
.contains("unknown graph type dependence `FUTURE_DEPENDENCE`"));
let mut endpoint = schema_properties("CONSTRAINT");
endpoint.insert(
key("constraintRuleType"),
Value::String("RELATIONSHIP_ENDPOINT_LABEL".to_owned()),
);
endpoint.insert(
key("schemaEntityType"),
Value::String("RELATIONSHIP".to_owned()),
);
endpoint.insert(
key("schemaPropertySchemaType"),
Value::String("SINGLE_ENTITY_TOKEN".to_owned()),
);
endpoint.insert(key("schemaPropertyIds"), Value::List(Vec::new()));
endpoint.insert(key("endpointLabelId"), Value::Integer(4));
assert!(parse_rule(
2,
&endpoint,
&labels,
&relationships,
&property_keys,
&mut SchemaMetadata::default(),
)
.unwrap_err()
.contains("schema property `endpointType` is missing"));
endpoint.insert(key("endpointType"), Value::String("MIDDLE".to_owned()));
assert!(parse_rule(
2,
&endpoint,
&labels,
&relationships,
&property_keys,
&mut SchemaMetadata::default(),
)
.unwrap_err()
.contains("unknown endpoint type `MIDDLE`"));
let mut required_label = schema_properties("CONSTRAINT");
required_label.insert(
key("constraintRuleType"),
Value::String("NODE_LABEL_EXISTENCE".to_owned()),
);
required_label.insert(
key("schemaPropertySchemaType"),
Value::String("SINGLE_ENTITY_TOKEN".to_owned()),
);
required_label.insert(key("schemaPropertyIds"), Value::List(Vec::new()));
assert!(parse_rule(
3,
&required_label,
&labels,
&relationships,
&property_keys,
&mut SchemaMetadata::default(),
)
.unwrap_err()
.contains("schema property `requiredLabelId` is missing"));
}
#[test]
fn converts_and_validates_property_type_serializations() {
assert_eq!(
property_type_user_description("LOCAL_TIME").unwrap(),
"LOCAL TIME"
);
assert_eq!(
property_type_user_description("LIST_STRING").unwrap(),
"LIST<STRING NOT NULL>"
);
assert_eq!(
property_type_user_description("VECTOR[coordinate=FLOAT64, dimensions=1536]").unwrap(),
"VECTOR<FLOAT NOT NULL>(1536)"
);
assert!(property_type_user_description("FUTURE_TYPE")
.unwrap_err()
.contains("unknown schema value type"));
assert!(
property_type_user_description("VECTOR[coordinate=FLOAT64, dimensions=0]")
.unwrap_err()
.contains("outside 1..=4096")
);
let labels = BTreeMap::from([(3, "Person".to_owned())]);
let property_keys = BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]);
let mut constraint = schema_properties("CONSTRAINT");
constraint.insert(
key("constraintRuleType"),
Value::String("PROPERTY_TYPE".to_owned()),
);
constraint.insert(key("propertyType"), Value::List(Vec::new()));
assert!(parse_rule(
4,
&constraint,
&labels,
&BTreeMap::new(),
&property_keys,
&mut SchemaMetadata::default(),
)
.unwrap_err()
.contains("has no allowed property types"));
}
#[test]
fn rejects_unknown_schema_token_ids() {
let error = parse_schema(
&schema_properties("INDEX"),
&BTreeMap::new(),
&BTreeMap::new(),
&BTreeMap::from([(7, "first".to_owned()), (8, "last".to_owned())]),
)
.unwrap_err();
assert!(error.contains("unknown entity token ID 3"));
}
}