levels-werror.js 761 B

12345678910111213141516171819202122232425262728293031323334
  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. /* Wrap the "checkFile" error. */
  18. return (callback(new verror.WError(
  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(err.toString());
  28. }
  29. });