@omnist-dev/omnist
    Preparing search index...

    Class WriteError

    A document -- or, since issue #150 (OSD-14, omnist-spec Sec5.9), a Schema -- cannot be represented losslessly (or at all) in the target format.

    Most throw sites are strict: true-only: .report holds the full WriteReport of every adjustment that would have been needed, so callers can inspect the structured list, not just the text. OSD-14 is the one exception -- a field label carrying a C0 control character (U+0000 to U+001F) has no OSD spelling at all (Sec5.3.1 bans the raw byte in a string body, and OSD's unescaping is weak), so toOsd throws this unconditionally, strict or not, the same "fail, don't invent" rule Sec8.3.8's E-6 already applies to every other writer case of this shape. .code/.path are populated only there (write.unsupported-value, the Schema path of the record holding the offending field -- Sec8.4 offers no way to quote a label inside a path); every other WriteError throw site continues to pass neither, so both are simply undefined. This is an additive widening of an existing public type, not a breaking change: no existing call site or catch site needs updating.

    Hierarchy (View Summary)

    Index
    • Parameters

      • message: string
      • report: unknown = undefined
      • Optionalcode: string
      • Optionalpath: string

      Returns WriteError

    cause?: unknown
    code: string | undefined

    Stable machine-readable error code (omnist-spec Sec8.3), when the throw site has one.

    message: string
    name: string
    path: string | undefined

    Schema/Document path of the offending construct (Sec8.4), when known.

    report: unknown

    Attached adjustment report when written in strict mode or reporting is enabled.

    stack?: string
    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

      const myObject = {};
      Error.captureStackTrace(myObject);
      myObject.stack; // Similar to `new Error().stack`

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      function a() {
      b();
      }

      function b() {
      c();
      }

      function c() {
      // Create an error without stack trace to avoid calculating the stack trace twice.
      const { stackTraceLimit } = Error;
      Error.stackTraceLimit = 0;
      const error = new Error();
      Error.stackTraceLimit = stackTraceLimit;

      // Capture the stack trace above function b
      Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
      throw error;
      }

      a();

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void