Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  io.invalid-config.test.ts

  Sprache: JAVA
 

import { describe, expect, it, vi } from "vitest";
import {
  createInvalidConfigError,
  formatInvalidConfigDetails,
  formatInvalidConfigLogMessage,
  logInvalidConfigOnce,
  throwInvalidConfig,
} from "./io.invalid-config.js";

describe("config io invalid config formatting", () => {
  it("formats issue details with sanitized paths and messages", () => {
    const details = formatInvalidConfigDetails([
      {
        path: "gateway.port",
        message: 'Expected number\\nreceived "bad"',
      },
      {
        path: "",
        message: "root problem",
      },
    ]);

    expect(details).toContain("- gateway.port:");
    expect(details).toContain("Expected number");
    expect(details).toContain("received");
    expect(details).toContain("- <root>: root problem");
  });

  it("formats the logger message with the escaped newline separator", () => {
    expect(formatInvalidConfigLogMessage("/tmp/openclaw.json""- gateway.port: bad")).toBe(
      "Invalid config at /tmp/openclaw.json:\\n- gateway.port: bad",
    );
  });

  it("creates INVALID_CONFIG errors with inline details", () => {
    const err = createInvalidConfigError("/tmp/openclaw.json""- gateway.port: bad") as Error & {
      code?: string;
      details?: string;
    };

    expect(err.message).toBe("Invalid config at /tmp/openclaw.json:\n- gateway.port: bad");
    expect(err.code).toBe("INVALID_CONFIG");
    expect(err.details).toBe("- gateway.port: bad");
  });

  it("logs invalid config details only once per path", () => {
    const logger = { error: vi.fn() };
    const loggedConfigPaths = new Set<string>();

    logInvalidConfigOnce({
      configPath: "/tmp/openclaw.json",
      details: "- gateway.port: bad",
      logger,
      loggedConfigPaths,
    });
    logInvalidConfigOnce({
      configPath: "/tmp/openclaw.json",
      details: "- gateway.port: worse",
      logger,
      loggedConfigPaths,
    });

    expect(logger.error).toHaveBeenCalledOnce();
    expect(logger.error).toHaveBeenCalledWith(
      "Invalid config at /tmp/openclaw.json:\\n- gateway.port: bad",
    );
  });

  it("throws INVALID_CONFIG after logging the formatted details", () => {
    const logger = { error: vi.fn() };

    expect(() =>
      throwInvalidConfig({
        configPath: "/tmp/openclaw.json",
        issues: [{ path: "nope", message: "Unknown key(s): nope" }],
        logger,
        loggedConfigPaths: new Set<string>(),
      }),
    ).toThrowError("Invalid config at /tmp/openclaw.json:\n- nope: Unknown key(s): nope");
    expect(logger.error).toHaveBeenCalledOnce();
  });
});

Messung V0.5 in Prozent
C=100 H=93 G=96

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik