Skip to content

Commit

Permalink
Report a path for UnknownModelCollection during model resolution (#…
Browse files Browse the repository at this point in the history
…1216)

### What

Like #1192, this PR adds a context to another error raised during the
`models` resolution step. Specifically, `UnknownModelCollection`.

### How

These PRs are extremely simple, it's just that there are going to be
dozens of them. When an error refers to a thing, you wrap that thing in
`Spanned`, and then try to extract the `path` at the error site. Most of
the time, it's pretty straightforward.

---------

Co-authored-by: Daniel Chambers <daniel@hasura.io>
V3_GIT_ORIGIN_REV_ID: d3ea71d3d9a42cbf804add54f5f6e75ab68c6765
  • Loading branch information
2 people authored and hasura-bot committed Oct 8, 2024
1 parent 7c4d34d commit 81bd72f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
3 changes: 3 additions & 0 deletions v3/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Added

- Added contexts to more MBS errors: when a model refers to a collection that
doesn't exist, the path to the offending reference will be reported.

### Fixed

- Fix local `docker-compose.yaml` file so that running `docker compose up`
Expand Down
20 changes: 13 additions & 7 deletions v3/crates/metadata-resolve/src/stages/models/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ pub(crate) fn resolve_model_source(
.schema
.collections
.get(model_source.collection.as_str())
.ok_or_else(|| ModelsError::UnknownModelCollection {
model_name: model.name.clone(),
data_connector: qualified_data_connector_name.clone(),
collection: model_source.collection.clone(),
.ok_or_else(|| crate::WithContext::Contextualised {
error: ModelsError::UnknownModelCollection {
model_name: model.name.clone(),
data_connector: qualified_data_connector_name.clone(),
collection: model_source.collection.value.clone(),
},
context: error_context::Context(vec![error_context::Step {
message: "Collection name given here".to_string(),
path: model_source.collection.path.clone(),
}]),
})?;
let source_collection_type =
DataConnectorObjectType::from(source_collection.collection_type.as_str());
Expand Down Expand Up @@ -103,7 +109,7 @@ pub(crate) fn resolve_model_source(
.map_err(|err| ModelsError::ModelCollectionArgumentMappingError {
data_connector_name: qualified_data_connector_name.clone(),
model_name: model.name.clone(),
collection_name: model_source.collection.clone(),
collection_name: model_source.collection.value.clone(),
error: err,
})?;

Expand All @@ -112,7 +118,7 @@ pub(crate) fn resolve_model_source(
.map(|issue| ModelsIssue::FunctionArgumentMappingIssue {
data_connector_name: qualified_data_connector_name.clone(),
model_name: model.name.clone(),
collection_name: model_source.collection.clone(),
collection_name: model_source.collection.value.clone(),
issue,
})
.collect();
Expand Down Expand Up @@ -147,7 +153,7 @@ pub(crate) fn resolve_model_source(
)
.map(Arc::new)
.map_err(ModelsError::from)?,
collection: model_source.collection.clone(),
collection: model_source.collection.value.clone(),
collection_type: source_collection_type,
type_mappings,
argument_mappings,
Expand Down
14 changes: 3 additions & 11 deletions v3/crates/open-dds/metadata.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,6 @@
},
"additionalProperties": false
},
"CollectionName": {
"$id": "https://hasura.io/jsonschemas/metadata/CollectionName",
"title": "CollectionName",
"description": "The name of a collection in a data connector.",
"type": "string"
},
"ColumnFieldMapping": {
"$id": "https://hasura.io/jsonschemas/metadata/ColumnFieldMapping",
"title": "ColumnFieldMapping",
Expand Down Expand Up @@ -2738,12 +2732,10 @@
"pattern": "^[_a-zA-Z][_a-zA-Z0-9]*$"
},
"collection": {
"$id": "https://hasura.io/jsonschemas/metadata/CollectionName",
"title": "CollectionName",
"description": "The collection in the data connector that backs this model.",
"allOf": [
{
"$ref": "#/definitions/CollectionName"
}
]
"type": "string"
},
"argumentMapping": {
"description": "Mapping from model argument names to data connector collection argument names.",
Expand Down
2 changes: 1 addition & 1 deletion v3/crates/open-dds/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub struct ModelSource {
pub data_connector_name: Spanned<DataConnectorName>,

/// The collection in the data connector that backs this model.
pub collection: CollectionName,
pub collection: Spanned<CollectionName>,

/// Mapping from model argument names to data connector collection argument names.
#[opendd(default)]
Expand Down

0 comments on commit 81bd72f

Please sign in to comment.