{"record":{"id":"add18b2d1e33e3c5","repo":"pentaho/pentaho-kettle","slug":"elemwithkey-is-not-defined","errorCode":null,"errorMessage":"${elemWithKey} is not defined.","messagePattern":"(.+?) is not defined\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/core-ui/src/main/resources/app/pentaho/lang/Collection.js","lineNumber":191,"sourceCode":"     * @param {string} [key] The element's key.\n     * @param {boolean} [assertExists=false] Indicates if an error should be thrown when\n     *     the collection does not contain an element with the given key.\n     *\n     * @return {pentaho.lang.ICollectionElement|*} The element with the given key,\n     *     if one is contained by the collection,\n     *     or {@link pentaho.lang.Collection#missingValue},\n     *     otherwise.\n     * @see pentaho.lang.Collection#getExisting\n     */\n    get: function(key, assertExists) {\n      var key2;\n      if(key != null &&\n         (key2 = this._castKey(key)) != null &&\n         O.hasOwn(this.__keys, key2)) {\n        return this.__keys[key2];\n      }\n\n      if(assertExists) throw new Error(this._sayElemWithKey(key2) + \" is not defined.\");\n\n      return this.missingValue;\n    },\n\n    /**\n     * Gets an existing element by its key.\n     *\n     * An error is thrown when\n     * the collection does not contain an element with the given key.\n     *\n     * @param {string} [key] The element's key.\n     * @return {pentaho.lang.ICollectionElement} The element with the given key.\n     * @see pentaho.lang.Collection#get\n     */\n    getExisting: function(key) {\n      return this.get(key, true);\n    },\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core-ui/src/main/resources/app/pentaho/lang/Collection.js#L173-L209","documentation":"Collection.get throws this when assertExists is true (as done by getExisting and by get(key, assertExists)) and no element with the given key exists in __keys. It is the collection's 'key not found' assertion, distinct from the non-asserting get which returns missingValue.","triggerScenarios":"collection.getExisting(key) with an unknown key; collection.get(key, true) where the key was never added or was already removed; passing an unnormalized key when a custom _castKey would map it differently.","commonSituations":"Looking up a visual role/field by a misspelled name; assuming an element is present before it is added; stale references to a key after remove() or clear(); case-sensitivity mismatches in keys.","solutions":["Verify the key exists with collection.has(key) before calling getExisting","Use collection.get(key) (non-asserting) if absence is an expected outcome and handle missingValue","Fix the key spelling/casing in the lookup","Add the element before looking it up, or check the lifecycle order (add happens later than the lookup)"],"exampleFix":"// before\nvar elem = list.getExisting('foo'); // throws if absent\n// after\nvar elem = list.has('foo') ? list.getExisting('foo') : null;","handlingStrategy":"validation","validationCode":"var elem = list.has(key) ? list.getExisting(key) : null;","typeGuard":"function findElem(list, key) {\n  return typeof key === 'string' && list.has(key) ? list.getExisting(key) : null;\n}","tryCatchPattern":"try {\n  var elem = list.getExisting(key);\n} catch (e) {\n  if (String(e.message).indexOf('is not defined') >= 0) {\n    var elem = null; // absence path\n  } else throw e;\n}","preventionTips":["Prefer has(key) or non-asserting get(key) when absence is expected","Verify key spelling/casing before lookups","Track element lifecycle so lookups never precede add or follow remove"],"tags":["collection","key-not-found"],"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"}