chrisdmacrae / atomic-algolia

An NPM package for running atomic updates to an Algolia indices
67 stars 13 forks source link

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sort' of undefined #14

Closed sparanoid closed 4 years ago

sparanoid commented 6 years ago

Output:

> project@2.0.3 algolia /path/to/project
> atomic-algolia

(node:42184) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sort' of undefined
    at idsFromIndex (/usr/local/lib/node_modules/atomic-algolia/lib/utils/idsFromIndex.js:15:9)
    at calculateOperations (/usr/local/lib/node_modules/atomic-algolia/lib/utils/calculateOperations.js:23:23)
    at /usr/local/lib/node_modules/atomic-algolia/lib/update.js:34:30
(node:42184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id:1)
(node:42184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Part of my algolia.json, I can post the full json if you need it:

[
      {
        "title": "测试用文档",
        "permalink": "http://0.0.0.0:4321/docs/test-doc/",
        "link": "/docs/test-doc/",
        "url": "/docs/test-doc/",
        "date": null,

          "modified": "2018-08-31T23:43:53+08:00",

        "author": {
          "name": "OpenBayes",
          "url": "https://openbayes.com/",
          "email": "hi@openbayes.com"
        },
        "html": "<h2 id=\"准备\">准备</h2>\n\n<h3 id=\"安装-kubectl\">安装 <code class=\"highlighter-rouge\">kubectl</code></h3>\n\n<p>在 mac 下:</p>\n\n<div class=\"highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>brew install kubectl\n</code></pre></div></div>\n\n<p>更多系统安装方式见 <a href=\"https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl\">Install and Set Up kubectl | Kubernetes</a>。</p>\n\n<p>执行 <code class=\"highlighter-rouge\">kubectl version --client</code> 测试 <code class=\"highlighter-rouge\">kubectl</code> 安装成功。</p>\n\n<div class=\"language-shell highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nv\">$ </span>kubectl version <span class=\"nt\">--client</span>\n\nClient Version: version.Info<span class=\"o\">{</span>Major:<span class=\"s2\">\"1\"</span>, Minor:<span class=\"s2\">\"10\"</span>, GitVersion:<span class=\"s2\">\"v1.10.0\"</span>, GitCommit:<span class=\"s2\">\"fc32d2f3698e36b93322a3465f63a14e9f0eaead\"</span>, GitTreeState:<span class=\"s2\">\"clean\"</span>, BuildDate:<span class=\"s2\">\"2018-03-27T00:13:02Z\"</span>, GoVersion:<span class=\"s2\">\"go1.9.4\"</span>, Compiler:<span class=\"s2\">\"gc\"</span>, Platform:<span class=\"s2\">\"darwin/amd64\"</span><span class=\"o\">}</span>\n</code></pre></div></div>\n\n<h3 id=\"获取-adminconf\">获取 <code class=\"highlighter-rouge\">admin.conf</code></h3>\n\n<p>如果没有 kubernetes master 的登录权限,请向 Kubernetes 管理员索要 <code class=\"highlighter-rouge\">admin.conf</code> 文件并命名为 <code class=\"highlighter-rouge\">~/.kube/config</code>。</p>\n\n<p>如果有 kubernetes master 登录权限,将 <code class=\"highlighter-rouge\">/etc/kubernetes/admin.conf</code> 拷贝到本地 <code class=\"highlighter-rouge\">~/.kube</code> 并重命名为 <code class=\"highlighter-rouge\">config</code>。<strong>注意</strong>,如果<code class=\"highlighter-rouge\">admin.conf</code> 下 <code class=\"highlighter-rouge\">clusters.cluster.server</code> 的地址为内网地址(如 aws 环境下的默认 ip 地址)而不是公网可以访问的外网地址,需要将其修改为外网地址才能从本地访问集群。</p>\n\n<p>执行命令 <code class=\"highlighter-rouge\">kubectl cluster-info</code> 测试集群链接成功。</p>\n\n<div class=\"language-shell highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nv\">$ </span>kubectl cluster-info\n\nKubernetes master is running at https://xxxx:6443\nKubeDNS is running at https://xxxx:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy\n\nTo further debug and diagnose cluster problems, use <span class=\"s1\">'kubectl cluster-info dump'</span><span class=\"nb\">.</span>\n</code></pre></div></div>\n\n<h2 id=\"用-kubectl-部署-tf-job\">用 kubectl 部署 tf-job</h2>\n\n<h3 id=\"准备-docker\">准备 docker</h3>\n\n<p>参见 <a href=\"https://github.com/kubeflow/tf-operator/tree/master/examples/tf_sample\">tf-operator/examples/tf_sample at master · kubeflow/tf-operator · GitHub</a> 准备模型训练所使用的 docker,其中应当包含:</p>\n\n<ol>\n  <li>训练数据的下载</li>\n  <li>数据的预处理</li>\n  <li>模型的训练</li>\n  <li>模型的保存和上传</li>\n</ol>\n\n<p><strong>注意</strong> 目前,kubeflow 集群不提供任何的存储服务,而只提供计算资源。一个训练使用的 docker 内需要提供数据的下载以及模型的上传,与 s3 等存储服务的对接将在近期展开。</p>\n\n<h3 id=\"部署-tf-job\">部署 tf-job</h3>\n\n<p>创建 <code class=\"highlighter-rouge\">tf_sample.yaml</code>:</p>\n\n<div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"na\">apiVersion</span><span class=\"pi\">:</span> <span class=\"s2\">\"</span><span class=\"s\">kubeflow.org/v1alpha1\"</span>\n<span class=\"na\">kind</span><span class=\"pi\">:</span> <span class=\"s2\">\"</span><span class=\"s\">TFJob\"</span>\n<span class=\"na\">metadata</span><span class=\"pi\">:</span>\n  <span class=\"na\">name</span><span class=\"pi\">:</span> <span class=\"s2\">\"</span><span class=\"s\">example-job\"</span>\n<span class=\"na\">spec</span><span class=\"pi\">:</span>\n  <span class=\"na\">replicaSpecs</span><span class=\"pi\">:</span>\n    <span class=\"pi\">-</span> <span class=\"na\">replicas</span><span class=\"pi\">:</span> <span class=\"s\">1</span>\n      <span class=\"na\">tfReplicaType</span><span class=\"pi\">:</span> <span class=\"s\">MASTER</span>\n      <span class=\"na\">template</span><span class=\"pi\">:</span>\n        <span class=\"na\">spec</span><span class=\"pi\">:</span>\n          <span class=\"na\">containers</span><span class=\"pi\">:</span>\n            <span class=\"pi\">-</span> <span class=\"na\">image</span><span class=\"pi\">:</span> <span class=\"s\">eisenxu/tf_sample:d4ef871-dirty-991dde4</span>\n              <span class=\"na\">name</span><span class=\"pi\">:</span> <span class=\"s\">tensorflow</span>\n          <span class=\"na\">restartPolicy</span><span class=\"pi\">:</span> <span class=\"s\">Never</span>\n    <span class=\"pi\">-</span> <span class=\"na\">replicas</span><span class=\"pi\">:</span> <span class=\"s\">1</span>\n      <span class=\"na\">tfReplicaType</span><span class=\"pi\">:</span> <span class=\"s\">WORKER</span>\n      <span class=\"na\">template</span><span class=\"pi\">:</span>\n        <span class=\"na\">spec</span><span class=\"pi\">:</span>\n          <span class=\"na\">containers</span><span class=\"pi\">:</span>\n            <span class=\"pi\">-</span> <span class=\"na\">image</span><span class=\"pi\">:</span> <span class=\"s\">eisenxu/tf_sample:d4ef871-dirty-991dde4</span>\n              <span class=\"na\">name</span><span class=\"pi\">:</span> <span class=\"s\">tensorflow</span>\n          <span class=\"na\">restartPolicy</span><span class=\"pi\">:</span> <span class=\"s\">Never</span>\n    <span class=\"pi\">-</span> <span class=\"na\">replicas</span><span class=\"pi\">:</span> <span class=\"s\">2</span>\n      <span class=\"na\">tfReplicaType</span><span class=\"pi\">:</span> <span class=\"s\">PS</span>\n      <span class=\"na\">template</span><span class=\"pi\">:</span>\n        <span class=\"na\">spec</span><span class=\"pi\">:</span>\n          <span class=\"na\">containers</span><span class=\"pi\">:</span>\n            <span class=\"pi\">-</span> <span class=\"na\">image</span><span class=\"pi\">:</span> <span class=\"s\">eisenxu/tf_sample:d4ef871-dirty-991dde4</span>\n              <span class=\"na\">name</span><span class=\"pi\">:</span> <span class=\"s\">tensorflow</span>\n          <span class=\"na\">restartPolicy</span><span class=\"pi\">:</span> <span class=\"s\">Never</span>\n</code></pre></div></div>\n\n<p>执行命令部署 tfjob</p>\n\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>kubectl <span class=\"nt\">-f</span> tf_sample.yaml\n</code></pre></div></div>\n\n<p>通过命令</p>\n\n<div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>kubectl get <span class=\"nt\">-o</span> yaml tfjobs example-job\n</code></pre></div></div>\n\n<p>查看任务执行进度。</p>\n\n<p>更多有关创建 tfjob 的细节请见 <a href=\"https://github.com/kubeflow/tf-operator/blob/master/README.md\">tf-operator/README.md at master · kubeflow/tf-operator · GitHub</a>。</p>\n\n<h2 id=\"参考\">参考</h2>\n\n<ol>\n  <li><a href=\"https://kubernetes.io/\">Kubernetes | Production-Grade Container Orchestration</a></li>\n  <li><a href=\"https://github.com/kubeflow/kubeflow/blob/master/user_guide.md#submitting-a-tensorflow-training-job\">kubeflow/user_guide.md at master · kubeflow/kubeflow · GitHub</a></li>\n  <li><a href=\"https://www.youtube.com/watch?v=xMaCC3uzBU8\">KubeFlow CPU/GPU Demo</a></li>\n</ol>",
        "content": "准备\n\n安装 kubectl\n\n在 mac 下:\n\nbrew install kubectl\n\n\n更多系统安装方式见 Install and Set Up kubectl | Kubernetes。\n\n执行 kubectl version --client 测试 kubectl 安装成功。\n\n$ kubectl version --client\n\nClient Version: version.Info{Major:\"1\", Minor:\"10\", GitVersion:\"v1.10.0\", GitCommit:\"fc32d2f3698e36b93322a3465f63a14e9f0eaead\", GitTreeState:\"clean\", BuildDate:\"2018-03-27T00:13:02Z\", GoVersion:\"go1.9.4\", Compiler:\"gc\", Platform:\"darwin/amd64\"}\n\n\n获取 admin.conf\n\n如果没有 kubernetes master 的登录权限,请向 Kubernetes 管理员索要 admin.conf 文件并命名为 ~/.kube/config。\n\n如果有 kubernetes master 登录权限,将 /etc/kubernetes/admin.conf 拷贝到本地 ~/.kube 并重命名为 config。注意,如果admin.conf 下 clusters.cluster.server 的地址为内网地址(如 aws 环境下的默认 ip 地址)而不是公网可以访问的外网地址,需要将其修改为外网地址才能从本地访问集群。\n\n执行命令 kubectl cluster-info 测试集群链接成功。\n\n$ kubectl cluster-info\n\nKubernetes master is running at https://xxxx:6443\nKubeDNS is running at https://xxxx:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy\n\nTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.\n\n\n用 kubectl 部署 tf-job\n\n准备 docker\n\n参见 tf-operator/examples/tf_sample at master · kubeflow/tf-operator · GitHub 准备模型训练所使用的 docker,其中应当包含:\n\n\n  训练数据的下载\n  数据的预处理\n  模型的训练\n  模型的保存和上传\n\n\n注意 目前,kubeflow 集群不提供任何的存储服务,而只提供计算资源。一个训练使用的 docker 内需要提供数据的下载以及模型的上传,与 s3 等存储服务的对接将在近期展开。\n\n部署 tf-job\n\n创建 tf_sample.yaml:\n\napiVersion: \"kubeflow.org/v1alpha1\"\nkind: \"TFJob\"\nmetadata:\n  name: \"example-job\"\nspec:\n  replicaSpecs:\n    - replicas: 1\n      tfReplicaType: MASTER\n      template:\n        spec:\n          containers:\n            - image: eisenxu/tf_sample:d4ef871-dirty-991dde4\n              name: tensorflow\n          restartPolicy: Never\n    - replicas: 1\n      tfReplicaType: WORKER\n      template:\n        spec:\n          containers:\n            - image: eisenxu/tf_sample:d4ef871-dirty-991dde4\n              name: tensorflow\n          restartPolicy: Never\n    - replicas: 2\n      tfReplicaType: PS\n      template:\n        spec:\n          containers:\n            - image: eisenxu/tf_sample:d4ef871-dirty-991dde4\n              name: tensorflow\n          restartPolicy: Never\n\n\n执行命令部署 tfjob\n\nkubectl -f tf_sample.yaml\n\n\n通过命令\n\nkubectl get -o yaml tfjobs example-job\n\n\n查看任务执行进度。\n\n更多有关创建 tfjob 的细节请见 tf-operator/README.md at master · kubeflow/tf-operator · GitHub。\n\n参考\n\n\n  Kubernetes | Production-Grade Container Orchestration\n  kubeflow/user_guide.md at master · kubeflow/kubeflow · GitHub\n  KubeFlow CPU/GPU Demo",
        "excerpt_html": "<h2 id=\"准备\">准备</h2>",
        "excerpt_text": "准备",
        "languages": null,
        "categories": [],
        "custom_ranking": {
          "position": null,
          "heading": null
        },
        "tags": [],
        "type": "doc"
      }

...
$ node -v
v10.9.0
JulienPradet commented 6 years ago

We (@mzanibelli and I) had the same issue just now, and we figured that the objects that we were trying to index were missing the objectID field (which is used to compare with the existing index).

However, this could still be improved by adding a warning in this file, imo : https://github.com/chrisdmacrae/atomic-algolia/blob/master/lib/utils/idsFromIndex.js#L11

chrisdmacrae commented 4 years ago

@JulienPradet @sparanoid this will be fixed today in 0.3.18.

Any hits w/o an object id are now ignored. A debug warning is now omitted, which you can see by running:

package.json

"scripts": {
  "algolia": "atomic-algolia"
}
DEBUG=true npm run Algolia
anthonyjdella commented 2 years ago

I was getting an UnhandledPromisRejectionWarning: ReferenceError: debug is not defined.

As @chrisdmacrae said, this was put there to warn when the objectID is missing. But for some reason, I was getting this exception.

Anyways, it did help me fix the issue because I just added an objectID into my index'd JSON.