{"record":{"id":"de3502b440d1277d","repo":"HKUDS/Vibe-Trading","slug":"unhandled-barrier-type-b-type","errorCode":null,"errorMessage":"Unhandled barrier type {b_type}","messagePattern":"Unhandled barrier type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/options.py","lineNumber":622,"sourceCode":"    ) * norm.cdf(eta * (y2 - sigma_sqrt_T))\n\n    # Cash rebate component\n    if rebate > 0.0:\n        E = rebate * df_r * (norm.cdf(eta * (x2 - sigma_sqrt_T)) - (hs_ratio ** (2.0 * mu)) * norm.cdf(eta * (y2 - sigma_sqrt_T)))\n    else:\n        E = 0.0\n\n    if opt_type == _CALL:\n        if b_type == \"down-and-out\":\n            price = (A - C + (rebate * df_r - E)) if K >= H else (B - D + (rebate * df_r - E))\n        elif b_type == \"down-and-in\":\n            price = (C + E) if K >= H else (A - B + D + E)\n        elif b_type == \"up-and-out\":\n            price = (rebate * df_r - E) if K >= H else (A - B + C - D + (rebate * df_r - E))\n        elif b_type == \"up-and-in\":\n            price = (A + E) if K >= H else (B - C + D + E)\n        else:\n            raise ValueError(f\"Unhandled barrier type {b_type}\")\n    else:  # PUT\n        if b_type == \"down-and-out\":\n            price = (A - B + C - D + (rebate * df_r - E)) if K >= H else (rebate * df_r - E)\n        elif b_type == \"down-and-in\":\n            price = (B - C + D + E) if K >= H else (A + E)\n        elif b_type == \"up-and-out\":\n            price = (B - D + (rebate * df_r - E)) if K >= H else (A - C + (rebate * df_r - E))\n        elif b_type == \"up-and-in\":\n            price = (A - B + D + E) if K >= H else (C + E)\n        else:\n            raise ValueError(f\"Unhandled barrier type {b_type}\")\n\n    return float(max(0.0, price))\n","sourceCodeStart":604,"sourceCodeEnd":636,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/options.py#L604-L636","documentation":"barrier_option_price dispatches the CALL pricing branch over the four canonical barrier types (down-and-out, down-and-in, up-and-out, up-and-in). Reaching the else clause means b_type is not one of them — in practice only possible if normalise_barrier_type's alias table is extended or bypassed, since the type was normalised earlier. It is a defensive internal invariant check for the call leg.","triggerScenarios":"Not reachable through the public API with stock aliases; triggered if the module's BARRIER_TYPES is monkey-patched, an unmapped alias slips through a patched _BARRIER_ALIASES, or internal code calls the branch with a raw string.","commonSituations":"Library maintainers adding a new barrier type (e.g. double-no-touch) and forgetting the call-leg dispatch; tests that patch the alias table; downstream forks that extend the enum.","solutions":["If extending barrier types, add matching elif branches in both the CALL and PUT legs plus tests.","Do not monkey-patch the alias tables; request the type upstream instead.","As an end user hitting this, report it — your installed copy is patched or inconsistent; reinstall the package."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    px = barrier_option_price(...)\nexcept ValueError as e:\n    if 'Unhandled barrier type' in str(e):\n        raise RuntimeError('inconsistent quantlib install: report upstream') from e\n    raise","preventionTips":["Do not monkey-patch alias tables; contribute new barrier types upstream with both call and put branches.","Pin the package version in production.","If forking, add dispatch-coverage tests for every alias."],"tags":["options","barrier-option","internal-invariant","unreachable-code"],"backgroundTag":"internal-invariant-violation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}