apache/hadoop · error · IOException

Unknown mode: ${mode}

Error message

Unknown mode: ${mode}

What it means

EventWriter(FSDataOutputStream, WriteMode) supports exactly two modes: WriteMode.JSON (writes "Avro-Json" header, JSON encoder) and WriteMode.BINARY ("Avro-Binary", binary encoder). Any other value - including null - throws IOException("Unknown mode"). With the stock two-value WriteMode enum this is a defensive guard for future/forked modes; via the public API it is only reachable by passing null.

Source

Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/jobhistory/EventWriter.java:79

   * avro encoding format supported by EventWriter.
   */
  public enum WriteMode { JSON, BINARY }
  private final WriteMode writeMode;
  private final boolean jsonOutput;  // Cache value while we have 2 modes

  @VisibleForTesting
  public EventWriter(FSDataOutputStream out, WriteMode mode)
      throws IOException {
    this.out = out;
    this.writeMode = mode;
    if (this.writeMode==WriteMode.JSON) {
      this.jsonOutput = true;
      out.writeBytes(VERSION);
    } else if (this.writeMode==WriteMode.BINARY) {
      this.jsonOutput = false;
      out.writeBytes(VERSION_BINARY);
    } else {
      throw new IOException("Unknown mode: " + mode);
    }
    out.writeBytes("\n");
    out.writeBytes(Event.SCHEMA$.toString());
    out.writeBytes("\n");
    if (!this.jsonOutput) {
      this.encoder = EncoderFactory.get().binaryEncoder(out, null);
    } else {
      this.encoder = EncoderFactory.get().jsonEncoder(Event.SCHEMA$, out);
    }
  }
  
  synchronized void write(HistoryEvent event) throws IOException { 
    Event wrapper = new Event();
    wrapper.setType(event.getEventType());
    wrapper.setEvent(event.getDatum());
    writer.write(wrapper, encoder);
    if (this.jsonOutput) {
      encoder.flush();

View on GitHub (pinned to 2add963021)

Solutions

  1. Always pass WriteMode.JSON or WriteMode.BINARY explicitly (JobHistory normally selects this for you).
  2. Null-check the mode before constructing the writer.
  3. In forks, wire every new WriteMode constant to a header string and encoder in this constructor before shipping.

Example fix

// before
EventWriter writer = new EventWriter(out, mode); // mode null -> Unknown mode: null

// after
WriteMode effective = (mode != null) ? mode : WriteMode.JSON;
EventWriter writer = new EventWriter(out, effective);
Defensive patterns

Strategy: validation

Validate before calling

if (mode != EventWriter.WriteMode.JSON && mode != EventWriter.WriteMode.BINARY) {
  throw new IllegalArgumentException("mode must be JSON or BINARY, got: " + mode);
}

Prevention

When it happens

Trigger: Passing a null WriteMode (uninitialized field, broken config plumbing) to the EventWriter constructor; or, in a fork, adding a WriteMode constant without updating this constructor.

Common situations: Bugs where the mode variable is never assigned; forked Hadoop adding e.g. XML mode; tests constructing EventWriter directly with default/null mode.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/e0f80c75b5a8b9d9. Report an issue: GitHub.