{"record":{"id":"d7d6ff5fc8a2d1ce","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-creating-an-element-in-the-shared-objects","errorCode":null,"errorMessage":"Unexpected error creating an element in the shared objects meta store","messagePattern":"Unexpected error creating an element in the shared objects meta store","errorType":"exception","errorClass":"MetaStoreException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/shared/SharedObjectsMetaStore.java","lineNumber":176,"sourceCode":"  public void createElement( String namespace, IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException, MetaStoreElementExistException {\n    try {\n      IMetaStoreElement exists = getElementByName( namespace, elementType, element.getId() );\n      if ( exists != null ) {\n        throw new MetaStoreException( \"The shared objects meta store already contains an element with type name '\"\n          + elementType.getName() + \"' and element name '\" + element.getName() );\n      }\n\n      if ( elementType.getName().equals( databaseElementType.getName() ) ) {\n        // convert the element to DatabaseMeta and store it in the shared objects file, then save the file\n        //\n        sharedObjects.storeObject( DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement( this, element ) );\n        sharedObjects.saveToFile();\n        return;\n      }\n      throw new MetaStoreException( \"Storing elements with element type name '\"\n        + elementType.getName() + \"' is not supported in the shared objects meta store\" );\n    } catch ( Exception e ) {\n      throw new MetaStoreException( \"Unexpected error creating an element in the shared objects meta store\", e );\n    }\n  }\n\n  @Override\n  public void deleteElement( String namespace, IMetaStoreElementType elementType, String elementId ) throws MetaStoreException {\n    try {\n      if ( elementType.getName().equals( databaseElementType.getName() ) ) {\n        sharedObjects.removeObject( DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement( this, getElement(\n          namespace, elementType, elementId ) ) );\n        sharedObjects.saveToFile();\n        return;\n      }\n    } catch ( Exception e ) {\n      throw new MetaStoreException( \"Unexpected error deleting an element in the shared objects meta store\", e );\n    }\n  }\n\n  public SharedObjects getSharedObjects() {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/shared/SharedObjectsMetaStore.java#L158-L194","documentation":"createElement() wraps any exception thrown during element creation (duplicate checks, DatabaseMeta conversion, shared-objects storeObject/saveToFile IO) into MetaStoreException with the generic message 'Unexpected error creating an element in the shared objects meta store'. The original cause is attached as the exception cause.","triggerScenarios":"Any failure inside createElement: the duplicate-name MetaStoreException itself is caught and re-wrapped, DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement throwing during conversion, storeObject() failing, or saveToFile() failing on IO errors.","commonSituations":"Corrupt shared.xml files, write-protected ~/.kettle directory, malformed element XML passed in, or duplicate-name exceptions being masked by the generic wrapper.","solutions":["Inspect e.getCause() of the MetaStoreException for the root error","Verify the shared objects file is writable and not corrupt (restore from .backup if needed)","Check for duplicate element names first (the duplicate error is re-wrapped here)","Validate the IMetaStoreElement content before calling createElement"],"exampleFix":"// before\n} catch ( Exception e ) {\n  throw new MetaStoreException( \"Unexpected error creating...\", e );\n}\n// after\n} catch ( MetaStoreElementExistException e ) {\n  throw e; // preserve specific error\n} catch ( Exception e ) {\n  throw new MetaStoreException( \"Unexpected error creating...\", e );\n}","handlingStrategy":"try-catch","validationCode":"if ( metaStore.getElementByName( ns, elementType, element.getName() ) != null ) {\n  throw new IllegalStateException( \"Duplicate element name: \" + element.getName() );\n}\njava.io.File f = new java.io.File( sharedObjects.getFilename() );\nif ( !f.getParentFile().canWrite() ) throw new IllegalStateException( \"Shared objects dir not writable\" );","typeGuard":null,"tryCatchPattern":"try {\n  metaStore.createElement( ns, type, element );\n} catch ( MetaStoreException e ) {\n  Throwable root = e;\n  while ( root.getCause() != null ) root = root.getCause();\n  logger.error( \"Element creation failed; root cause: {}\", root.getMessage(), e );\n}","preventionTips":["Always read e.getCause() — the top message is generic by design","Pre-check duplicates and file writability before creation","Log the full exception chain, not just getMessage()"],"tags":["metastore","wrapped-exception","pdi"],"backgroundTag":"internal-invariant-violation","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}