itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

Fixed: Improved exception message on failed schema import

Open DebottamMandal123 opened this issue 1 month ago • 2 comments

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 Improved-exception-messages-testing_image

DebottamMandal123 avatar Nov 23 '25 21:11 DebottamMandal123

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 23 '25 21:11 CLAassistant

I suggest you instead use this opportunity to introduce a new ITwinError interface for schema related errors instead of propagation the ErrorNumber insanity.

kabentley avatar Nov 25 '25 13:11 kabentley