{"record":{"id":"cd6178d4a9c08d9a","repo":"pydantic/monty","slug":"invalid-display-format-format-expected-type-msg-or-msg","errorCode":null,"errorMessage":"Invalid display format: '${format}'. Expected 'type-msg' or 'msg'","messagePattern":"Invalid display format: '(.+?)'\\. Expected 'type-msg' or 'msg'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/errors.ts","lineNumber":62,"sourceCode":"  }\n\n  /** Information about the inner Python exception. */\n  get exception(): ExceptionInfo {\n    return { typeName: this.typeName, message: this.innerMessage }\n  }\n\n  /**\n   * Formats the exception: `'type-msg'` for `ExceptionType: message`,\n   * `'msg'` (default) for just the message.\n   */\n  display(format: 'type-msg' | 'msg' = 'msg'): string {\n    switch (format) {\n      case 'msg':\n        return this.innerMessage\n      case 'type-msg':\n        return this.innerMessage ? `${this.typeName}: ${this.innerMessage}` : this.typeName\n      default:\n        throw new Error(`Invalid display format: '${format}'. Expected 'type-msg' or 'msg'`)\n    }\n  }\n}\n\n/**\n * Raised when the fed code cannot be parsed. The inner exception is always a\n * `SyntaxError`.\n */\nexport class MontySyntaxError extends MontyError {\n  private readonly tracebackText: string\n\n  constructor(message: string, tracebackText = '') {\n    super('SyntaxError', message)\n    this.name = 'MontySyntaxError'\n    this.tracebackText = tracebackText\n  }\n\n  /**","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/errors.ts#L44-L80","documentation":"Thrown by the `display()` method of a Monty error wrapper when its `format` argument is neither the string `'type-msg'` nor `'msg'` (nor omitted, which defaults to `'msg'`). It is a plain developer-facing argument-validation error: the caller passed an unsupported format literal to the formatter, so no exception data is involved. Fix the call site to pass one of the two allowed format strings.","triggerScenarios":"Calling error.display('short'), display('full'), or a dynamically computed format string that is not exactly one of the two supported literals.","commonSituations":"Guessing format names from other logging libraries; user-configurable display options flowing through unchecked; typos like 'type_msg'.","solutions":["Call display('msg') for the bare message or display('type-msg') for 'Type: message'","Validate/whitelist the format value before calling display","Fall back: const text = fmt === 'msg' || fmt === 'type-msg' ? err.display(fmt) : err.display('type-msg')"],"exampleFix":"// before\nconst text = err.display('short');\n// after\nconst text = err.display('type-msg');","handlingStrategy":"type-guard","validationCode":"const DISPLAY_FORMATS = ['msg', 'type-msg'];\nif (!DISPLAY_FORMATS.includes(fmt)) fmt = 'type-msg';","typeGuard":"function isDisplayFormat(v) {\n  return v === 'msg' || v === 'type-msg';\n}","tryCatchPattern":"try {\n  text = err.display(fmt);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Invalid display format')) {\n    text = err.display('type-msg');\n  } else throw e;\n}","preventionTips":["Only use the literal strings 'msg' and 'type-msg'","Whitelist user-configurable format options before passing them to display()","Centralize error formatting in one helper that hardcodes the valid formats"],"tags":["typescript","error-display","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}