{"record":{"id":"e9821daffeeb15f9","repo":"pydantic/monty","slug":"dynamic-diagnostics-from-the-type-checker","errorCode":null,"errorMessage":"(dynamic: diagnostics from the type checker)","messagePattern":"\\(dynamic: diagnostics from the type checker\\)","errorType":"exception","errorClass":"MontyTypingError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/session.ts","lineNumber":217,"sourceCode":"    const answerer = new TurnAnswerer(this.native, this.instances, options.externalLookup, options.os)\n    let turn = (await this.native.feed(\n      code,\n      prepareInputs(options.inputs, this.instances),\n      mountsToNative(options.mount),\n      { cwd: options.cwd, skipTypeCheck: options.skipTypeCheck ?? false },\n      onPrint,\n    )) as NativeTurn\n    for (;;) {\n      switch (turn.kind) {\n        case 'complete':\n          printTarget.throwIfFailed()\n          return restore(turn.value, this.instances)\n        case 'error':\n          printTarget.throwIfFailed()\n          throw montyErrorFromNative(turn.exception)\n        case 'typingError':\n          printTarget.throwIfFailed()\n          throw new MontyTypingError(turn.diagnostics)\n        case 'crashed':\n          throw this.poison(new MontyCrashedError(turn.message, turn))\n        case 'protocol':\n          throw this.poison(new ProtocolError(turn.message))\n      }\n      // Print failures take precedence. On a suspension the worker is waiting\n      // for a resume we will never send — poison so the next feed fails cleanly\n      // (matches Python pool: discard checkout when print fails mid-suspend).\n      try {\n        printTarget.throwIfFailed()\n      } catch (err) {\n        throw this.poison(err instanceof Error ? err : new Error(String(err)))\n      }\n      try {\n        turn = await answerer.answer(turn, onPrint)\n      } catch (err) {\n        // A handler that throws instead of answering leaves the worker\n        // suspended, awaiting a resume that will never come — the session","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/session.ts#L199-L235","documentation":"The worker's type checker rejected the code before execution; the session throws `MontyTypingError` carrying the checker's diagnostics (messages, file/line info from the turn). This is a per-turn, dynamic error — the diagnostics text comes from the type checker, not a fixed string.","triggerScenarios":"`session.feedRun(code, { typeCheck: true })` (or checkout with `typeCheck: true`) where the code fails type checking, e.g. wrong attribute use, argument type mismatch against typeshed stubs.","commonSituations":"Running a Monty-incompatible API the stubs don't know, feeding dynamically built code that doesn't type-check, upgrading code that used to skip type checking.","solutions":["Read `error.diagnostics` and fix the reported lines in the fed code","Set `typeCheck: false` in checkout/feed options if type checking is not required","Narrow or annotate the code (type hints) so the checker accepts the intended types"],"exampleFix":"// before\nconst result = await session.feedRun('x.upper()', { typeCheck: true }) // x: int\n// after\nconst result = await session.feedRun(\"x: str = 'hi'\\nx.upper()\", { typeCheck: true })","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await session.feedRun(code, { typeCheck: true })\n} catch (e) {\n  if (e instanceof MontyTypingError) {\n    for (const d of e.diagnostics) console.error(`${d.location ?? ''}: ${d.message}`)\n  } else throw e\n}","preventionTips":["Run type checking in CI/staging so production turns never hit fresh diagnostics","Keep fed code aligned with the vendored typeshed subset Monty supports","Only enable `typeCheck` on turns where the cost/blocking is acceptable"],"tags":["typescript","type-checking","diagnostics"],"backgroundTag":"unexpected-response-shape","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}