{"record":{"id":"69244326cb37ac51","repo":"pentaho/pentaho-kettle","slug":"error-0004-repository-not-found","errorCode":"ERROR_0004_REPOSITORY_NOT_FOUND","errorMessage":"RepositoryConnectionUtils.ERROR_0004_REPOSITORY_NOT_FOUND","messagePattern":"RepositoryConnectionUtils\\.ERROR_0004_REPOSITORY_NOT_FOUND","errorType":"error_code","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/RepositoryConnectionUtils.java","lineNumber":99,"sourceCode":"      throw new KettleException( BaseMessages.getString(\n        \"RepositoryConnectionUtils.ERROR_0018_META_REPOSITORY_NOT_POPULATED\" ), e ); //$NON-NLS-1$\n    }\n\n    if ( logger.isDebugEnabled() ) {\n      logger.debug( \" Finding repository metadata\" );\n    }\n    // Find the specified repository.\n    RepositoryMeta repositoryMeta = null;\n    try {\n      if ( isSingleDiServerInstance ) {\n        repositoryMeta = repositoriesMeta.findRepository( SINGLE_DI_SERVER_INSTANCE );\n      } else {\n        repositoryMeta = repositoriesMeta.findRepository( repositoryName );\n      }\n\n\n    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG,\n        \"RepositoryConnectionUtils.ERROR_0004_REPOSITORY_NOT_FOUND\", repositoryName ), e ); // $NON-NLS-1$\n    }\n\n    if ( repositoryMeta == null ) {\n      if ( logger.isDebugEnabled() && logBuffer != null ) {\n        logger.debug( logBuffer.getBuffer().toString() );\n      }\n      throw new KettleException( BaseMessages.getString( PKG,\n        \"RepositoryConnectionUtils.ERROR_0004_REPOSITORY_NOT_FOUND\", repositoryName ) ); //$NON-NLS-1$\n    }\n\n    if ( logger.isDebugEnabled() ) {\n      logger.debug( \" Getting repository instance \" ); //$NON-NLS-1$\n    }\n    Repository repository = null;\n    try {\n      repository =\n        PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta.getId(),","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/RepositoryConnectionUtils.java#L81-L117","documentation":"While resolving the named repository inside connectToRepository, findRepository(repositoryName) (or the direct-index branch) is executed inside a try block; if lookup throws, the code rethrows a KettleException with ERROR_0004_REPOSITORY_NOT_FOUND including the repository name. It signals the requested repository definition does not exist in the loaded metadata.","triggerScenarios":"Calling connectToRepository with a repositoryName that findRepository cannot match against the loaded RepositoriesMeta — typo'd name, repositories.xml lacking that entry, or an exception during lookup.","commonSituations":"Connecting programmatically after a fresh install where repositories.xml has no registered repositories; renamed repository in Spoon while scripts still use the old name; case-sensitivity mismatch in the repository name; CI servers pointing at a repository defined only on developers' machines.","solutions":["List available repositories with new RepositoriesMeta().readData() and getRepository(i).getName(), then use an exact existing name.","Register the repository in Spoon (Connect / Repository manager) or add it programmatically and call writeData().","Check for exact name/case/whitespace match — findRepository compares strings literally.","Verify you are reading the repositories.xml you think you are (HOME vs KETTLE_HOME differences).","If using a direct repository index, confirm the supplied index is in range (the else-branch path)."],"exampleFix":"// before: hardcoded name that may not exist\nRepository rep = RepositoryConnectionUtils.connectToRepository(log, null, \"ProdRepo\", user, pass, null, false);\n// after: verify the name exists first\nRepositoriesMeta rmi = new RepositoriesMeta();\nrmi.readData();\nif (rmi.findRepository(\"ProdRepo\") == null) {\n  throw new IllegalStateException(\"Available: \" + IntStream.range(0, rmi.nrRepositories()).mapToObj(i -> rmi.getRepository(i).getName()).collect(Collectors.joining(\", \")));\n}\nRepository rep = RepositoryConnectionUtils.connectToRepository(log, null, \"ProdRepo\", user, pass, null, false);","handlingStrategy":"validation","validationCode":"RepositoriesMeta meta = new RepositoriesMeta();\nmeta.readData();\nboolean exists = java.util.stream.IntStream.range(0, meta.nrRepositories()).anyMatch(i -> meta.getRepository(i).getName().equals(repoName));\nif (!exists) throw new IllegalArgumentException(\"Unknown repository: \" + repoName);","typeGuard":null,"tryCatchPattern":"try { rep = RepositoryConnectionUtils.connectToRepository(...); } catch (KettleException e) { if (e.getMessage().contains(\"ERROR_0004\")) { log.error(\"Repository name not found; check repositories.xml\", e); } throw e; }","preventionTips":["Load repository names dynamically instead of hardcoding","Keep repository names consistent across environments","Trim and compare names case-exactly as findRepository does"],"tags":["repository-connection","lookup","not-found","pdi"],"backgroundTag":"record-not-found","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"}