errorcodes.rst 1.4 KB

123456789101112131415161718192021222324252627282930
  1. .. SPDX-License-Identifier: GPL-2.0
  2. bcachefs private error codes
  3. ----------------------------
  4. In bcachefs, as a hard rule we do not throw or directly use standard error
  5. codes (-EINVAL, -EBUSY, etc.). Instead, we define private error codes as needed
  6. in fs/bcachefs/errcode.h.
  7. This gives us much better error messages and makes debugging much easier. Any
  8. direct uses of standard error codes you see in the source code are simply old
  9. code that has yet to be converted - feel free to clean it up!
  10. Private error codes may subtype another error code, this allows for grouping of
  11. related errors that should be handled similarly (e.g. transaction restart
  12. errors), as well as specifying which standard error code should be returned at
  13. the bcachefs module boundary.
  14. At the module boundary, we use bch2_err_class() to convert to a standard error
  15. code; this also emits a trace event so that the original error code be
  16. recovered even if it wasn't logged.
  17. Do not reuse error codes! Generally speaking, a private error code should only
  18. be thrown in one place. That means that when we see it in a log message we can
  19. see, unambiguously, exactly which file and line number it was returned from.
  20. Try to give error codes names that are as reasonably descriptive of the error
  21. as possible. Frequently, the error will be logged at a place far removed from
  22. where the error was generated; good names for error codes mean much more
  23. descriptive and useful error messages.