Skip to content

Commit

Permalink
SchemaMerger shall only merge into dynamic schemas (#7114)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanApfel-Bentley committed Sep 19, 2024
1 parent 94037c4 commit 4e22022
Show file tree
Hide file tree
Showing 22 changed files with 1,494 additions and 1,208 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-editing",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-editing"
}
13 changes: 10 additions & 3 deletions core/ecschema-editing/src/Merging/SchemaMerger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getSchemaDifferences, type SchemaDifferenceResult } from "../Differenci
import { SchemaMergingVisitor } from "./SchemaMergingVisitor";
import { SchemaMergingWalker } from "./SchemaMergingWalker";
import type { SchemaEdits } from "./Edits/SchemaEdits";
import { ECEditingStatus, SchemaEditingError } from "../Editing/Exception";

/**
* Defines the context of a Schema merging run.
Expand Down Expand Up @@ -79,9 +80,15 @@ export class SchemaMerger {
);
}

const schema = await this._editor.getSchema(targetSchemaKey);
if (schema === undefined) {
throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
const schema = await this._editor.getSchema(targetSchemaKey).catch((error: Error) => {
if (error instanceof SchemaEditingError && error.errorNumber === ECEditingStatus.SchemaNotFound) {
throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
}
throw error;
});

if (!schema.customAttributes || !schema.customAttributes.has("CoreCustomAttributes.DynamicSchema")) {
throw new Error(`The target schema '${targetSchemaKey.name}' is not dynamic. Only dynamic schemas are supported for merging.`);
}

const visitor = new SchemaMergingVisitor({
Expand Down
Loading

0 comments on commit 4e22022

Please sign in to comment.