{"record":{"id":"e421f7f3b1b3537f","repo":"jax-ml/jax","slug":"check-error-takes-an-error-as-argument-got-type","errorCode":null,"errorMessage":"check_error takes an Error as argument, got type {type(error)} instead.","messagePattern":"check_error takes an Error as argument, got type (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/checkify.py","lineNumber":1418,"sourceCode":"  >>> def f(x):\n  ...   checkify.check(x>0, \"must be positive!\")\n  ...   return x\n  >>> def with_inner_jit(x):\n  ...   checked_f = checkify.checkify(f)\n  ...   # a checkified function can be jitted\n  ...   error, out = jax.jit(checked_f)(x)\n  ...   checkify.check_error(error)\n  ...   return out\n  >>> _ = with_inner_jit(1)  # no failed check\n  >>> with_inner_jit(-1)  # doctest: +IGNORE_EXCEPTION_DETAIL\n  Traceback (most recent call last):\n    ...\n  jax._src.JaxRuntimeError: must be positive!\n  >>> # can re-checkify\n  >>> error, _ = checkify.checkify(with_inner_jit)(-1)\n  \"\"\"\n  if not isinstance(error, Error):\n    raise TypeError('check_error takes an Error as argument, '\n                     f'got type {type(error)} instead.')\n  _check_error(error, debug=False)\n","sourceCodeStart":1400,"sourceCodeEnd":1421,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/checkify.py#L1400-L1421","documentation":"checkify.check_error(error) is the post-run step that surfaces any failed checks collected by checkify; it only accepts an instance of checkify.Error (the first element of the tuple returned by checkify()). The source isinstance-checks the argument and raises TypeError otherwise. This commonly happens when callers pass the function result or the second tuple element instead of the Error object.","triggerScenarios":"Calling check_error on something that isn't an Error: e.g. err, _ = checkify(f); check_error(f_result) — passing the function's return value instead of err, or unpacking the tuple in the wrong order, or passing None after forgetting that checkify returns (Error, functools.partial).","commonSituations":"New users assume check_error takes the checked function's output. Also re-checkifying: after error is transformed, passing the wrapped function or a jax.Array where the Error should be.","solutions":["Use the first element of the tuple returned by checkify: error, checked_fn = checkify(f); ...; checkify.check_error(error)","Verify you're not passing the function output, None, or the partial function","If re-checkifying a jitted function, thread the outer and inner Error values through explicitly as shown in the checkify docs"],"exampleFix":"// before\nerror, checked_fn = checkify(f)\nout = checked_fn(args)\ncheckify.check_error(out)  # wrong: that's f's return\n// after\nerror, checked_fn = checkify(f)\nout = checked_fn(args)\ncheckify.check_error(error)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from jax._src.checkify import Error, check_error\n\ndef is_error_obj(x) -> bool:\n    return isinstance(x, Error)","tryCatchPattern":"try:\n    checkify.check_error(error)\nexcept TypeError as e:\n    raise TypeError(f'pass the Error from checkify(), not {type(error)}') from e","preventionTips":["Always unpack: error, checked_fn = checkify(f) and call check_error(error)","Name the tuple element 'error' at every call site to avoid mixing it up with outputs"],"tags":["jax","checkify","typeerror","api-misuse"],"backgroundTag":"wrong-argument-passed","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}