模板上的以下简单函数通常会失败,因为user对象未定义,即使我已登录:
Template.hello.userData = function() {
var user = Meteor.users.findOne(Meteor.userId());
return user.emails[0].address;
};
Run Code Online (Sandbox Code Playgroud)
它很容易复制:
Uncaught TypeError: Cannot read property 'emails' of undefined阴险的是"通常"部分:它有时会成功,因此可能存在竞争条件......并且可能是依赖项被加载的顺序.
我实际上是在一个更复杂的应用程序中点击这个,试图访问我登录用户的"profile"属性(存在,我保证).它在不同的浏览器中提供略有不同的错误消息 这是Chrome中的堆栈跟踪:
Exception from Deps recompute: TypeError: Cannot read property 'profile' of undefined
at Object.Template.workbook.owner (http://localhost:3000/client/client.js?153b3db62478692678dd9fdf9f1a9dd0b6b6a76e:130:21)
at apply (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:276:24)
at invoke (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:301:12)
at http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:365:30
at Object.Spark.labelBranch (http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:1171:14)
at branch (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:355:20)
at http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:364:18
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?13ab483e8a3c795d9991577e65e811cd0b827997:130:11)
at template (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:358:7) debug.js:41
Exception … 如果我每次都可以运行以下脚本,source ./script.sh但如果直接将其作为 执行,则大约 80% 的情况会失败./script.sh。
#!/bin/bash
signing_input="Hi."
signature=$(echo -n "$signing_input" | openssl dgst -sha256 -sign private.pem)
echo -n "$signing_input" | openssl dgst -sha256 -verify public.pem -signature <(echo -n "$signature")
Run Code Online (Sandbox Code Playgroud)
因此,如果我“获取”该内容或逐行运行,我总是会得到:Verified OK
...但是如果我在脚本中运行它,我通常但并不总是得到:Error verifying data
如果我先将签名保存到文件中,我会得到相同的结果。
我.pem这样生成文件:
openssl ecparam -name secp256k1 -genkey -noout -out private.pem
openssl ec -in private.pem -pubout -out public.pem
Run Code Online (Sandbox Code Playgroud)
...我是否每次重复使用它们或重新生成它们并不重要。
我在 Mac M1 上运行 iTerm2 和 zsh。