Skip to content

Commit

Permalink
source-http-ingest: use proper schema uri
Browse files Browse the repository at this point in the history
Fixes a bug in the source-http-ingest connector where it would use the
incorrect uri in cases where the collection schema already contained an
`$id`. Now it uses the uri that was actually resolved while building the
schema.

Also tweaks the logging of errors to use the more complete degub
representation.
  • Loading branch information
psFried committed Oct 9, 2024
1 parent 1019b0e commit dd5ea2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source-http-ingest/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ async fn handle_webhook(
{
Ok(resp) => resp,
Err(err) => {
tracing::error!(error = %err, "failed to handle request");
// Format the error to include causes when rendering to the logs.
let error_str = format!("{err:?}");
tracing::error!(error = %error_str, "failed to handle request");
let body = serde_json::json!({ "error": err.to_string() });
(StatusCode::INTERNAL_SERVER_ERROR, Json(body))
}
Expand Down Expand Up @@ -281,8 +283,13 @@ impl Handler {

let schema_value = serde_json::from_str::<Value>(&binding.collection.write_schema_json)
.context("parsing write_schema_json")?;
let uri = url::Url::parse("http://not.areal.host/").unwrap();
let schema = json::schema::build::build_schema(uri.clone(), &schema_value)?;
let schema = json::schema::build::build_schema(
url::Url::parse("http://not.areal.host/").unwrap(),
&schema_value,
)?;
// We must get the resolved uri after building the schema, since the one we pass in is
// only used for schemas that don't already have an absolute url as their `$id`.
let schema_url = schema.curi.clone();

// We intentionally leak the memory here in order to get a `&'static Schema`, because
// the schema index only works with references. The workaround would be to add a
Expand All @@ -299,7 +306,7 @@ impl Handler {
collections_by_path.insert(
path,
CollectionHandler {
schema_url: uri,
schema_url,
schema_index: index,
binding_index,
id_header: binding.resource_config.id_from_header,
Expand Down
1 change: 1 addition & 0 deletions source-http-ingest/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn open_json() -> serde_json::Value {
"collection": {
"name": "aliceCo/test/webhook-data",
"write_schema_json": {
"$id": "file:///some/fake/path.json",
"type": "object",
"properties": {
"_meta": {
Expand Down

0 comments on commit dd5ea2c

Please sign in to comment.