Fixed: Improved exception message on failed schema import
Fixes #8656 Improves exception handling during schema import operations to provide clearer and more actionable error messages.
Summary of Changes
1. ECDb Error Improvements (core/backend/src/ECDb.ts):
-
Added pre-validation for schema file existence (fs.existsSync / fs.accessSync)
-
Throw structured IModelStatus.FileNotFound errors including file path context
-
Wrapped importSchema native call with contextual exception handling
2. IModelDb Enhancements (core/backend/src/IModelDb.ts):
-
Introduced createSchemaImportError helper for consistent error messaging
-
Pre-validation for imported schema file paths
-
Improved context propagation for:
- File load failures - XML import failures - Schema sync failures
3. Regression Fix (core/backend/src/test/hubaccess/Rebase.test.ts):
-
Corrected incorrect usage of importSchemas in existing test
-
Now writes schema XML to a temp file before import
4. Added New Tests:
- New suite: core/backend/src/test/standalone/SchemaImportErrors.test.ts
-Covers:
- Missing file path → FileNotFound
- Invalid schema content → detailed contextual error message
Validation:
1. Automated:
- rush build
- Test suites (new + updated) — All passed
Manual:
- Verified clear messaging on missing file scenarios
📸 Screenshot of test results
I suggest you instead use this opportunity to introduce a new ITwinError interface for schema related errors instead of propagation the ErrorNumber insanity.