···11+.. SPDX-License-Identifier: GPL-2.022+33+bcachefs private error codes44+----------------------------55+66+In bcachefs, as a hard rule we do not throw or directly use standard error77+codes (-EINVAL, -EBUSY, etc.). Instead, we define private error codes as needed88+in fs/bcachefs/errcode.h.99+1010+This gives us much better error messages and makes debugging much easier. Any1111+direct uses of standard error codes you see in the source code are simply old1212+code that has yet to be converted - feel free to clean it up!1313+1414+Private error codes may subtype another error code, this allows for grouping of1515+related errors that should be handled similarly (e.g. transaction restart1616+errors), as well as specifying which standard error code should be returned at1717+the bcachefs module boundary.1818+1919+At the module boundary, we use bch2_err_class() to convert to a standard error2020+code; this also emits a trace event so that the original error code be2121+recovered even if it wasn't logged.2222+2323+Do not reuse error codes! Generally speaking, a private error code should only2424+be thrown in one place. That means that when we see it in a log message we can2525+see, unambiguously, exactly which file and line number it was returned from.2626+2727+Try to give error codes names that are as reasonably descriptive of the error2828+as possible. Frequently, the error will be logged at a place far removed from2929+where the error was generated; good names for error codes mean much more3030+descriptive and useful error messages.