pentaho/pentaho-kettle · error · Error

is not defined.

Error message

${elemWithKey} is not defined.

What it means

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.

Solutions

  1. Verify the key exists with collection.has(key) before calling getExisting
  2. Use collection.get(key) (non-asserting) if absence is an expected outcome and handle missingValue
  3. Fix the key spelling/casing in the lookup
  4. Add the element before looking it up, or check the lifecycle order (add happens later than the lookup)

Example fix

// before
var elem = list.getExisting('foo'); // throws if absent
// after
var elem = list.has('foo') ? list.getExisting('foo') : null;
Defensive patterns

Strategy: validation

Validate before calling

var elem = list.has(key) ? list.getExisting(key) : null;

Type guard

function findElem(list, key) {
  return typeof key === 'string' && list.has(key) ? list.getExisting(key) : null;
}

Try / catch

try {
  var elem = list.getExisting(key);
} catch (e) {
  if (String(e.message).indexOf('is not defined') >= 0) {
    var elem = null; // absence path
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/add18b2d1e33e3c5. Report an issue: GitHub.

Appendix: source

Thrown at plugins/core-ui/src/main/resources/app/pentaho/lang/Collection.js:191

     * @param {string} [key] The element's key.
     * @param {boolean} [assertExists=false] Indicates if an error should be thrown when
     *     the collection does not contain an element with the given key.
     *
     * @return {pentaho.lang.ICollectionElement|*} The element with the given key,
     *     if one is contained by the collection,
     *     or {@link pentaho.lang.Collection#missingValue},
     *     otherwise.
     * @see pentaho.lang.Collection#getExisting
     */
    get: function(key, assertExists) {
      var key2;
      if(key != null &&
         (key2 = this._castKey(key)) != null &&
         O.hasOwn(this.__keys, key2)) {
        return this.__keys[key2];
      }

      if(assertExists) throw new Error(this._sayElemWithKey(key2) + " is not defined.");

      return this.missingValue;
    },

    /**
     * Gets an existing element by its key.
     *
     * An error is thrown when
     * the collection does not contain an element with the given key.
     *
     * @param {string} [key] The element's key.
     * @return {pentaho.lang.ICollectionElement} The element with the given key.
     * @see pentaho.lang.Collection#get
     */
    getExisting: function(key) {
      return this.get(key, true);
    },

View on GitHub (pinned to f3058517a1)