gitbutlerapp/gitbutler · error
Error when registering schema
Error message
Error when registering schema {} for type {} registered at {}
The registered dependent type {} has a different signature than what is expected. This indicates a potential name collision. Consider renaming one of the types with either `#[serde(rename = ...)]` or `#[schemars(rename = ...)]`.
What it means
While registering a schema, but-ts found an already-registered dependent type (a `$defs`/`definitions` entry) whose schema body differs from the schema previously registered under the same name. Since `$ref` resolution requires identical bodies, this signals a name collision between two different types, and generation aborts.
Solutions
- Rename one of the colliding dependent types with `#[serde(rename = ...)]` / `#[schemars(rename = ...)]` so the `$defs` names are unique.
- Register the dependent type explicitly with `register_sdk_type!()` so the definitions reconcile to a single shared schema.
- Compare the two schemas referenced by the error to confirm whether the shape difference is intended or a stale duplicate.
Example fix
// before (crate B) #[derive(JsonSchema)] pub struct CommitId(pub String); // after #[derive(JsonSchema)] #[schemars(rename = "CommitIdV2")] pub struct CommitId(pub String);
Defensive patterns
Strategy: validation
Validate before calling
let def_names: HashSet<_> = schema["$defs"].as_object().unwrap().keys().collect();
let already: HashSet<_> = existing.keys().collect();
let overlaps: Vec<_> = def_names.intersection(&already).collect();
if !overlaps.is_empty() { /* verify shapes match or rename */ } Prevention
- Register shared dependent types once, centrally, instead of letting each schema inline its own copy.
- Avoid same-named helper types across crates used by the SDK.
- Regenerate TS bindings locally after adding nested types.
When it happens
Trigger: Registering a type whose schema inlines a `$defs` entry with a name that was already registered by another type, but with a different shape, so `root_equals_def` comparison fails in `collect_all_schemas`.
Common situations: Two crates each define a helper type with the same name (e.g. `CommitId`) used as a dependency of registered SDK types; a type was renamed only at the top level, leaving dependent definitions colliding.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Error when registering schema
- Error when registering schema
- existing GitMeta key
- existing GitMeta key
- existing GitMeta key
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/fd4ddac7a933a365.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-ts/src/main.rs:437
t.registration_location,
duplicate.type_name,
duplicate.registration_location
);
} else {
existing_names.insert(t.name.as_ref(), t);
}
}
for t in &types {
if let Some(obj) = t.schema.as_object()
&& let Some(serde_json::Value::Object(defs)) =
obj.get("$defs").or_else(|| obj.get("definitions"))
{
for (def_name, def_schema) in defs {
if let Some(entry) = existing_names.get(&def_name.as_ref()) {
let entry_schema = entry.schema.clone().to_value();
if !root_equals_def(&entry_schema, def_schema, def_name) {
bail!(
"Error when registering schema {} for type {} registered at {}\n\nThe registered dependent type {} has a different signature than what is expected. This indicates a potential name collision. Consider renaming one of the types with either `#[serde(rename = ...)]` or `#[schemars(rename = ...)]`.\n",
t.name,
t.type_name,
t.registration_location,
def_name
)
}
} else {
bail!(
"Error when registering schema {} for type {} registered at {}\n\nMissing dependent type {}. Consider deriving `JsonSchema` on the type and registering it with `register_sdk_type!()`.\n",
t.name,
t.type_name,
t.registration_location,
def_name
)
}
}
}View on GitHub (pinned to 58e5313667)