
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
error-watch
Advanced tools
根据 TraceKit 改造。 改动点:
es6 对源文件进行改写,根据功能拆分成小文件便于维护;rollup ,方便打成 UMD、ES 包,压缩代码;jasmine 改成了 Jest。npm i error-watch
import ErrorWatch from 'error-watch';
/**
* 错误监控回调函数
* @param stack {Object|null} 依次根据 Error 对象属性 stacktrace、stack、message和调用链 callers 来解析出错误行列等信息
* @param isWindowError {Boolean} 是否触发 window 监听事件,手动 try/catch 获取 err 解析为 false
* @param error {Error|null} 原始 err
*/
function receiveError(stack, isWindowError, error) {
const data = encodeURIComponent(JSON.stringify({
...stack, // 错误解析的对象
// isWindowError
url: window.location.href, // 报错页面
}));
// img 上报
// 注意分析数据有可能过大,需要考虑 ajax?
new Image().src = 'https://your-websize.com/api/handleError?data=' + data;
}
// 监听错误
ErrorWatch.report.subscribe(receiveError);
<script src="./dist/errorWatch.min.js"></script>
<scritp>
ErrorWatch.report.subscribe(function() {...});
</script>
Object 否则是 null,可以用来结合 SourceMap 定位错误。{
"mode": "stack",
"name": "ReferenceError",
"message": "thisIsAbug is not defined",
"stack": [
{
"url": "http://localhost:7001/public/js/traceKit.min.js",
"func": "Object.makeError",
"args": [],
"line": 1,
"column": 9435,
"context": null
},
{
"url": "http://localhost:7001/public/demo.html",
"func": "?",
"args": [],
"line": 49,
"column": 12,
"context": null
}
]
}
try {
/*
* your code
*/
throw new Error('oops');
} catch (e) {
ErrorWatch.report(e);
}
{
...stack,
errorStack: error && error.stack,
}
{
"mode": "stack",
"name": "ReferenceError",
"message": "thisIsAbug is not defined",
"stack": [
{
"url": "http://localhost:7001/public/js/traceKit.min.js",
"func": "Object.makeError",
"args": [],
"line": 1,
"column": 9435,
"context": null
},
{
"url": "http://localhost:7001/public/demo.html",
"func": "?",
"args": [],
"line": 49,
"column": 12,
"context": null
}
],
"errorStack": "ReferenceError: thisIsAbug is not defined\n at Object.makeError (http://localhost:7001/public/js/traceKit.min.js:1:9435)\n at http://localhost:7001/public/demo.html:49:12",
"url": "http://localhost:7001/public/demo.html"
}
mode 是 resource,来区分资源加载错误。{
"message": "img is load error",
"mode": "resource",
"name": "http://domain/404.jpg",
"stack": null,
"url": "http://localhost:7001/public/demo.html"
}
Api.foo = function Api_foo() {
};
const bar = function barFn() {
};
npm run build 根据 rollup.config.js 配置文件进行打包。npm test 单元测试。阅读源码前,可以参考下关于JS错误知识的一些讨论 错误监控原理分析。
FAQs
We found that error-watch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.