pump = require('pump')

pump简介

https://github.com/terinjokes/gulp-uglify/blob/master/docs/why-use-pump/README.md#why-use-pump

当使用来自Node.js的管道时,错误不会通过管道流向前传播,如果目标流关闭,源流也不会关闭。pump模块将这些问题规范化,并在回调中传递错误。

pump可以使我们更容易找到代码出错位置。

A common gulpfile example

A common pattern in gulp files is to simply return a Node.js stream, and expect the gulp tool to handle errors.

gulp文件中的一个常见模式是简单地返回一个Node.js流,并期待gulp工具能处理错误

// example of a common gulpfile
var gulp = require('gulp');
var uglify = require('gulp-uglify'); gulp.task('compress', function () {
// returns a Node.js stream, but no handling of error messages
return gulp.src('lib/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist'));
});

There’s an error in one of the JavaScript files, but that error message is the opposite of helpful. You want to know what file and line contains the error. So what is this mess?

这里有一个错误在某个JavaScript文件中,但是这些错误信息并没有起到什么作用。我们真正想要知道的是哪个文件的哪一行出现了这些错误。

When there’s an error in a stream, the Node.js stream fire the 'error' event, but if there’s no handler for this event, it instead goes to the defined uncaught exception handler. The default behavior of the uncaught exception handler is documented:

当在流中出现了错误时,将会触发'error'事件,但是如果这里的事件没有handler的话,它将会定义一个没有捕捉的异常handler,如下文档说明:

By default, Node.js handles such exceptions by printing the stack trace to stderr and exiting.默认情况下,Node.js通过将堆栈跟踪打印到stderr和退出来处理这些异常

Handling the Errors

Since allowing the errors to make it to the uncaught exception handler isn’t useful, we should handle the exceptions properly. Let’s give that a quick shot.

即然如果不处理异常将默认为uncaught exception handler(这是没有用的),那么我们就应该恰当地对异常进行处理

var gulp = require('gulp');
var uglify = require('gulp-uglify'); gulp.task('compress', function () {
return gulp.src('lib/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist'))
.on('error', function(err) { //添加一个异常处理
console.error('Error in compress task', err.toString());
});
});

Unfortunately, Node.js stream’s pipe function doesn’t forward errors through the chain, so this error handler only handles the errors given by gulp.dest. Instead we need to handle errors for each stream.

但是这个异常处理是不会通过链来传递错误的,所以它只会处理来自 gulp.dest的错误。那么如果我们要处理每一个流的错误的话,就要像下面一样,每个流都进行错误处理

var gulp = require('gulp');
var uglify = require('gulp-uglify'); gulp.task('compress', function () {
function createErrorHandler(name) {
return function (err) {
console.error('Error from ' + name + ' in compress task', err.toString());
};
} return gulp.src('lib/*.js')
.on('error', createErrorHandler('gulp.src'))
.pipe(uglify())
.on('error', createErrorHandler('uglify'))
.pipe(gulp.dest('dist'))
.on('error', createErrorHandler('gulp.dest'));
});

This is a lot of complexity to add in each of your gulp tasks, and it’s easy to forget to do it. In addition, it’s still not perfect, as it doesn’t properly signal to gulp’s task system that the task has failed. We can fix this, and we can handle the other pesky issues with error propogations with streams, but it’s even more work!

这样就会变得很复杂,而且你也很容易就忘记这么做。所以我们需要使用pump

Using pump

The pump module is a cheat code of sorts. It’s a wrapper around the pipe functionality that handles these cases for you, so you can stop hacking on your gulpfiles, and get back to hacking new features into your app.

它是用来处理上面这些情况的pipe的包装器,这样您就可以停止对您的gulpfile文件进行黑客攻击,并重新对您的应用程序进行黑客攻击

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pump = require('pump'); gulp.task('compress', function (cb) {
pump([
gulp.src('lib/*.js'),
uglify(),
gulp.dest('dist')
],
cb //回调函数
);
});

The gulp task system provides a gulp task with a callback, which can signal successful task completion (being called with no arguments), or a task failure (being called with an Error argument). Fortunately, this is the exact same format pump uses!

Now it’s very clear what plugin the error was from, what the error actually was, and from what file and line number.

这样我们就能够看见是什么触发了error,在哪个文件的哪一行

这只是一个简单的了解,如果想要更深入的学习请自学https://github.com/pump-io/pump.io

之后如果看了这部分再写出来

pump模块的学习-metamask的更多相关文章

  1. python模块的学习

    # time 模块 import time print(time.time()) #当前的时间挫 #time.sleep(3) #休息3秒钟,这3秒cpu不工作的 print(time.gmtime( ...

  2. requsets模块的学习

    requests模块的学习 使用之前 pip install requests 发起get,post,请求获取响应 response = requests.get(url,headers) # 发起g ...

  3. Spark的Rpct模块的学习

    Spark的Rpct模块的学习 Spark的Rpc模块是1.x重构出来可,以前的代码中大量使用了akka的类,为了把akka从项目的依赖中移除,所有添加了该模块.先看下该模块的几个主要的类   使用E ...

  4. retrying模块的学习

    retrying模块的学习 我们在写爬虫的过程中,经常遇到爬取失败的情况,这个时候我们一般会通过try块去进行重试,但是每次都写那么一堆try块,真的是太麻烦,所以今天就来说一个比较pythonic的 ...

  5. AngularJs HTML DOM、AngularJS 事件以及模块的学习(5)

    今天的基础就到了操作DOM,事件和模块的学习,其实我个人感觉学习起来AngularJS并没有想象中的那么的艰难,可能是因为这个太基础化吧,但是我们从初学开始就应该更加的自信一些,后来我可能会写一个小的 ...

  6. Python学习---重点模块的学习【all】

    time     [时间模块] import time # print(help(time)) # time模块的帮助 print(time.time()) # 时间戳 print(time.cloc ...

  7. Python模块——loguru日志模块简单学习

    Python loguru模块简单学习 首先安装模块:pip install logoru,然后引入模块: from loguru import logger 1.直接输出到console logge ...

  8. Request模块入门学习

    使用指令npm install --save request来安装模块,然后使用var request = require('request')完成引用. 对于GET请求,主要是获取目的url中数据. ...

  9. gulp学习-metamask前端使用

    https://www.gulpjs.com.cn/docs/getting-started/ ,这个是3.9.0版本 后面发现安装的版本是4.0.0,看下面这个: https://github.co ...

随机推荐

  1. Oracle入门《Oracle介绍》第一章1-4 Oracle 用户管理

    1.Oracle 默认用户 只有用合法的用户帐号才能访问Oracle数据库 Oracle 有几个默认的数据库用户 数据库中所有数据字典表和视图都存储在 SYS 模式中.SYS用户主要用来维护系统信息和 ...

  2. T-SQL:开窗函数(十二)

    1.基本概念 开窗函数分为两个部分分别是 1.聚合,排名,偏移,分布函数 . 2.开窗分区,排序,框架. 下面举个例子 SELECT empid, ordermonth, val, SUM(val) ...

  3. jQuery 【事件】【dom 操作】

    事件  hover( function(){},function(){})   --  鼠标移入移出事件   toggle(function(){},function(){},function(){} ...

  4. 以前没有写笔记的习惯,现在慢慢的发现及时总结是多么的重要。 这一篇文章主要关于java多线程一些常见的疑惑点。因为讲解多线程的书籍和文章已经很多了,所以我也不好意思多说,嘻嘻嘻、大家可以去参考一些那些书籍。我这个文章主要关于实际的一些问题。同时也算是我以后复习的资料吧,。还请大家多多指教。 同时希望多结交一些技术上的朋友。谢谢。

    在java中要想实现多线程,有两种手段,一种是继续Thread类,另外一种是实现Runable接口. 以下就是我们常见的问题了: 1. 为什么我们不能直接调用run()方法呢? 我的理解是:线程的运行 ...

  5. Ashampoo Driver Updater - 阿香婆驱动安装

    Ashampoo Driver Updater 让系统更完美 – 永远有最新的驱动,出错或旧的驱动是每个电脑系统的恶梦.时不时,驱动会丢失或不可避免的过时.Ashampoo Driver Update ...

  6. 安装 kubernetes v1.11.1

    kubernetes 版本 v1.11.1 系统版本:Centos 7.4 3.10.0-693.el7.x86_64 master: 192.168.0.205 node1: 192.168.0.2 ...

  7. HTML的语义化和一些简单优化

    1.什么是语义化? 必应网典的解释 语义化是指用合理HTML标记以及其特有的属性去格式化文档内容.通俗地讲,语义化就是对数据和信息进行处理,使得机器可以理解. 语义化的(X)HTML文档有助于提升你的 ...

  8. 关于Bootstrap fileinput 上传新文件,移除时触发服务器同步删除的配置

    在Bootstrap fileinput中移除预览文件时可以通过配置initialPreviewConfig: [ { url:'deletefile',key:fileid } ] 来同步删除服务器 ...

  9. 惊闻企业Web应用生成平台 活字格 V4.0 免费了,不单可视化设计器免费,服务器也免费!

    官网消息: 针对活字格开发者,新版本完全免费!您可下载活字格 Web 应用生成平台 V4.0 Updated 1,方便的创建各类 Web 应用系统,任意部署,永不过期. 我之前学习过活字格,也曾经向用 ...

  10. 利用搜狐新闻语料库训练100维的word2vec——使用python中的gensim模块

    关于word2vec的原理知识参考文章https://www.cnblogs.com/Micang/p/10235783.html 语料数据来自搜狐新闻2012年6月—7月期间国内,国际,体育,社会, ...