OtterMind/Chat2DB · error · IllegalArgumentException

Unsupported VARCHAR unit: {unit}

Error message

Unsupported VARCHAR unit: {unit}

What it means

Thrown by SUNDBSqlGuards.requireUnit when a VARCHAR size unit, after trimming, is neither CHAR nor BYTE. SUNDB VARCHAR length semantics accept only those two units; anything else is rejected to prevent injecting tokens into the DDL.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-sundb/src/main/java/ai/chat2db/plugin/sundb/SUNDBSqlGuards.java:96

            throw invalid("column type", columnType);
        }
        scanExpression(trimmed, true, "column type");
        return trimmed;
    }

    /**
     * Validates a VARCHAR size unit: only CHAR/BYTE are legal. Anything else is
     * rejected to block DDL injection.
     */
    public static String requireUnit(String unit) {
        String trimmed = StringUtils.trimToEmpty(unit);
        if ("CHAR".equalsIgnoreCase(trimmed)) {
            return "CHAR";
        }
        if ("BYTE".equalsIgnoreCase(trimmed)) {
            return "BYTE";
        }
        throw new IllegalArgumentException("Unsupported VARCHAR unit: " + unit);
    }

    public static String requireConstraintType(String constraintType) {
        String normalized = StringUtils.trimToEmpty(constraintType).toUpperCase(Locale.ROOT);
        if (CONSTRAINT_TYPES.contains(normalized)) {
            return normalized;
        }
        throw new IllegalArgumentException("Unsupported SUNDB constraint type: " + constraintType);
    }

    public static String requireNullOrder(String nullOrder) {
        String normalized = StringUtils.trimToEmpty(nullOrder).toUpperCase(Locale.ROOT);
        if (normalized.isEmpty()) {
            return "";
        }
        if ("NULLS FIRST".equals(normalized) || "NULL FIRST".equals(normalized)) {
            return "NULLS FIRST";
        }

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Set the unit to 'CHAR' or 'BYTE'.
  2. If the column does not need explicit length semantics, omit the unit entirely rather than sending a placeholder.
  3. Map non-SUNDB units (OCTETS->BYTE, CODEUNITS->CHAR) before populating the model.

Example fix

// before
col.setLengthUnit("OCTETS");
// -> Unsupported VARCHAR unit

// after
col.setLengthUnit("BYTE");
Defensive patterns

Strategy: validation

Validate before calling

String u = unit == null ? "" : unit.trim();
if (!"CHAR".equalsIgnoreCase(u) && !"BYTE".equalsIgnoreCase(u)) {
    throw new IllegalArgumentException("Reject VARCHAR unit: " + unit);
}

Type guard

static boolean isValidSundbUnit(String u) {
    return u != null && ("CHAR".equalsIgnoreCase(u.trim()) || "BYTE".equalsIgnoreCase(u.trim()));
}

Prevention

When it happens

Trigger: Setting a VARCHAR column's length unit to a value other than CHAR/BYTE - e.g. 'CODEUNITS', 'OCTETS', or a stray string. An empty/null unit also fails.

Common situations: Cross-dialect metadata using 'CHARACTER_LENGTH'/'OCTETS'; UI defaulting a unit field to a placeholder; a copy-paste of a full type like 'VARCHAR(10 CHAR)' into the unit field.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/b12079cb035e72c5. Report an issue: GitHub.