{"record":{"id":"fd5b2c446d9cea3b","repo":"gitbutlerapp/gitbutler","slug":"error-when-registering-schema-for-type-regis-fd5b2c","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-ts/src/main.rs","lineNumber":446,"sourceCode":"    for t in &types {\n        if let Some(obj) = t.schema.as_object()\n            && let Some(serde_json::Value::Object(defs)) =\n                obj.get(\"$defs\").or_else(|| obj.get(\"definitions\"))\n        {\n            for (def_name, def_schema) in defs {\n                if let Some(entry) = existing_names.get(&def_name.as_ref()) {\n                    let entry_schema = entry.schema.clone().to_value();\n                    if !root_equals_def(&entry_schema, def_schema, def_name) {\n                        bail!(\n                            \"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\",\n                            t.name,\n                            t.type_name,\n                            t.registration_location,\n                            def_name\n                        )\n                    }\n                } else {\n                    bail!(\n                        \"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\",\n                        t.name,\n                        t.type_name,\n                        t.registration_location,\n                        def_name\n                    )\n                }\n            }\n        }\n    }\n\n    // Order output types by name\n    types.sort_by(|a, b| a.name.cmp(&b.name));\n\n    Ok(types\n        .into_iter()\n        .map(|s| (s.name.to_string(), s.schema))\n        .collect())","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-ts/src/main.rs#L428-L464","documentation":"When registering a schema, but-ts walks the generated `$defs`/`definitions` of a type's schema and requires every dependent type to already be registered. A `$ref` to a name that is not in `existing_names` means a referenced `JsonSchema` type was never registered, so the generated binding would contain a dangling reference; the tool aborts.","triggerScenarios":"Registering a type via `register_sdk_type!()` whose schema references a nested type that does not derive `JsonSchema` registration — i.e. the dependency was never passed to `register_sdk_type!()` itself.","commonSituations":"Adding a field of a new nested type to a registered struct and forgetting to register the nested type; conditional compilation (`#[cfg]`) hiding the dependency registration on some platforms; a dependency removed from the registration list during refactoring.","solutions":["Derive `JsonSchema` on the missing dependent type and add a `register_sdk_type!()` call for it in the same source crate.","If the dependency should be inlined, annotate the field with `#[schemars(inline)]` instead of relying on a `$ref`.","Check the `def_name` in the error against the registration list in crates/but-ts to confirm which type is missing."],"exampleFix":"// before\n// (no registration for Author)\npub struct Commit { pub author: Author }\n// after\nregister_sdk_type!(crate::author::Author);\npub struct Commit { pub author: Author }","handlingStrategy":"validation","validationCode":"for dep in &schema[\"$defs\"] {\n    assert!(registered.contains_key(dep.key()), \"unregistered dependency: {}\", dep.key());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every type reachable from a registered type must derive JsonSchema and be registered with register_sdk_type!().","When adding a field of a new type, immediately add its registration.","Run but-ts as part of CI to catch missing registrations before release."],"tags":["code-generation","schema","missing-registration","json-schema"],"backgroundTag":"missing-dependency","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}