levels-verror.js 795 B

123456789101112131415161718192021222324252627282930313233343536
  1. var extsprintf = require('extsprintf');
  2. var fs = require('fs');
  3. var verror = require('../lib/verror');
  4. function checkFile(filename, callback) {
  5. fs.stat(filename, function (err) {
  6. if (err)
  7. /* Annotate the "stat" error with what we were doing. */
  8. return (callback(new verror.VError(err,
  9. 'failed to check "%s"', filename)));
  10. /* ... */
  11. return (callback());
  12. });
  13. }
  14. function handleRequest(filename, callback) {
  15. checkFile('/nonexistent', function (err) {
  16. if (err)
  17. /* Annotate the "checkFile" error. */
  18. return (callback(new verror.VError(
  19. err, 'request failed')));
  20. /* ... */
  21. return (callback());
  22. });
  23. }
  24. handleRequest('/nonexistent', function (err) {
  25. if (err) {
  26. console.log(err.message);
  27. console.log(extsprintf.sprintf('%r', err));
  28. }
  29. /* ... */
  30. });