Ruby 中的编组字符串

发布于 2024-12-07 20:17:59 字数 5876 浏览 1 评论 0原文

我在使用 Capistrano 时遇到错误。我已将错误范围缩小到这行代码:

puts message

其中“message”是通过 net-ssh 来自删除服务器的字符串。

因此,我尝试创建一个重现此错误的 .rb 文件。应该很容易...我只需 Marshal.dump(message),将其提供的内容复制/粘贴到脚本中的 Marshal.load(...) 中。

但是当我这样做时,我的单个 .rb 文件可以完美地工作。

所以我检查了我的应用程序,当我在 capistrano 中编组并立即解组字符串时,它起作用了。因此,在编组过程中有些东西丢失了,它阻止了我可靠地复制错误。

我正在使用 jruby:

jruby 1.6.4 (ruby-1.9.2-p136) (2011-08-23 17ea768) (Java HotSpot(TM) Client VM 1.6.0_26) [Windows 7-x86-java]

put 上的错误

ByteBuffer.java:352:in `wrap': java.lang.IndexOutOfBoundsException
        from ChannelDescriptor.java:618:in `write'
        from RubyIO.java:1386:in `fwrite'
        from RubyIO.java:1319:in `write'
        from RubyIO$i$1$0$write.gen:65535:in `call'
        from RubyClass.java:686:in `finvoke'
        from RuntimeHelpers.java:548:in `invoke'
        from RubyBasicObject.java:358:in `callMethod'
        from RubyIO.java:2297:in `write'
        from RubyIO.java:2283:in `putsArray'
        from RubyIO.java:2252:in `puts'
        from RubyKernel.java:522:in `puts'
        from RubyKernel$s$0$0$puts.gen:65535:in `call'
        from JavaMethod.java:630:in `call'
        from DynamicMethod.java:207:in `call'
        from CachingCallSite.java:167:in `call'
        from FCallOneArgNode.java:36:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:154:in `yield'
        from Block.java:130:in `yield'
        from RubyString.java:6830:in `each_lineCommon19'
        from RubyString.java:6801:in `each_lineCommon19'
        from RubyString.java:6790:in `lines'
        from RubyString$i$lines.gen:65535:in `call'
        from JavaMethod.java:442:in `call'
        from RubyClass.java:544:in `finvoke'
        from RuntimeHelpers.java:541:in `invoke'
        from RubyBasicObject.java:382:in `callMethod'
        from RubyEnumerator.java:190:in `each'
        from RubyEnumerator$i$0$0$each.gen:65535:in `call'
        from CachingCallSite.java:142:in `callBlock'
        from CachingCallSite.java:153:in `callIter'
        from CallNoArgBlockNode.java:64:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:276:in `call'
        from DefaultMethod.java:211:in `call'
        from CachingCallSite.java:235:in `call'
        from FCallThreeArgNode.java:40:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:255:in `call'
        from DefaultMethod.java:203:in `call'
        from RubyClass.java:582:in `finvoke'
        from RubyBasicObject.java:1697:in `send19'
        from RubyKernel.java:2121:in `send19'
        from RubyKernel$s$send19.gen:65535:in `call'
        from JavaMethod.java:300:in `call'
        from CachingCallSite.java:235:in `call'
        from CallThreeArgNode.java:61:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:191:in `yield'
        from Interpreted19Block.java:122:in `call'
        from Block.java:89:in `call'
        from RubyProc.java:274:in `call'
        from RubyProc.java:262:in `call19'
        from RubyProc$i$0$0$call19.gen:65535:in `call'
        from DynamicMethod.java:227:in `call'
        from DynamicMethod.java:223:in `call'
        from CachingCallSite.java:235:in `call'
        from CallThreeArgNode.java:61:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:191:in `yield'
        from Interpreted19Block.java:122:in `call'
        from Block.java:89:in `call'
        from RubyProc.java:274:in `call'
        from RubyProc.java:262:in `call19'
        from RubyProc$i$0$0$call19.gen:65535:in `call'
        from DynamicMethod.java:219:in `call'
        from DynamicMethod.java:215:in `call'
        from CachingCallSite.java:201:in `call'
        from CallTwoArgNode.java:59:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:190:in `call'
        from DefaultMethod.java:179:in `call'
        from CachingCallSite.java:312:in `cacheAndCall'
        from CachingCallSite.java:169:in `call'
        from CallOneArgNode.java:57:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:212:in `call'
        from DefaultMethod.java:187:in `call'
        from RubyClass.java:563:in `finvoke'
        from RubyBasicObject.java:1691:in `send19'
        from RubyKernel.java:2117:in `send19'
        from RubyKernel$s$send19.gen:65535:in `call'
        from JavaMethod.java:283:in `call'

它持续的时间比这更长,但它只是一堆动态方法调用。

该错误还在 puts "#{message}"puts "#{message.strip}" 上呈现不同的错误

I'm encountering a bug using Capistrano. I've narrowed down the bug to literally this line of code:

puts message

Where "message" is a string that has come from a remove server via net-ssh.

So I'm trying to create a single .rb file that reproduces this error. Should be easy... I just Marshal.dump(message), copy/paste what it gives me into a Marshal.load(...) in my script.

But when I do this, my single .rb file works flawlessly.

So I checked my app and when I marshal and immediately unmarshal the string in capistrano, it works. So something is getting lost in marshaling and its preventing me from duplicating the error reliably.

I'm using jruby:

jruby 1.6.4 (ruby-1.9.2-p136) (2011-08-23 17ea768) (Java HotSpot(TM) Client VM 1.6.0_26) [Windows 7-x86-java]

The error on puts

ByteBuffer.java:352:in `wrap': java.lang.IndexOutOfBoundsException
        from ChannelDescriptor.java:618:in `write'
        from RubyIO.java:1386:in `fwrite'
        from RubyIO.java:1319:in `write'
        from RubyIO$i$1$0$write.gen:65535:in `call'
        from RubyClass.java:686:in `finvoke'
        from RuntimeHelpers.java:548:in `invoke'
        from RubyBasicObject.java:358:in `callMethod'
        from RubyIO.java:2297:in `write'
        from RubyIO.java:2283:in `putsArray'
        from RubyIO.java:2252:in `puts'
        from RubyKernel.java:522:in `puts'
        from RubyKernel$s$0$0$puts.gen:65535:in `call'
        from JavaMethod.java:630:in `call'
        from DynamicMethod.java:207:in `call'
        from CachingCallSite.java:167:in `call'
        from FCallOneArgNode.java:36:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:154:in `yield'
        from Block.java:130:in `yield'
        from RubyString.java:6830:in `each_lineCommon19'
        from RubyString.java:6801:in `each_lineCommon19'
        from RubyString.java:6790:in `lines'
        from RubyString$i$lines.gen:65535:in `call'
        from JavaMethod.java:442:in `call'
        from RubyClass.java:544:in `finvoke'
        from RuntimeHelpers.java:541:in `invoke'
        from RubyBasicObject.java:382:in `callMethod'
        from RubyEnumerator.java:190:in `each'
        from RubyEnumerator$i$0$0$each.gen:65535:in `call'
        from CachingCallSite.java:142:in `callBlock'
        from CachingCallSite.java:153:in `callIter'
        from CallNoArgBlockNode.java:64:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:276:in `call'
        from DefaultMethod.java:211:in `call'
        from CachingCallSite.java:235:in `call'
        from FCallThreeArgNode.java:40:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:255:in `call'
        from DefaultMethod.java:203:in `call'
        from RubyClass.java:582:in `finvoke'
        from RubyBasicObject.java:1697:in `send19'
        from RubyKernel.java:2121:in `send19'
        from RubyKernel$s$send19.gen:65535:in `call'
        from JavaMethod.java:300:in `call'
        from CachingCallSite.java:235:in `call'
        from CallThreeArgNode.java:61:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:191:in `yield'
        from Interpreted19Block.java:122:in `call'
        from Block.java:89:in `call'
        from RubyProc.java:274:in `call'
        from RubyProc.java:262:in `call19'
        from RubyProc$i$0$0$call19.gen:65535:in `call'
        from DynamicMethod.java:227:in `call'
        from DynamicMethod.java:223:in `call'
        from CachingCallSite.java:235:in `call'
        from CallThreeArgNode.java:61:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
        from Interpreted19Block.java:203:in `evalBlockBody'
        from Interpreted19Block.java:191:in `yield'
        from Interpreted19Block.java:122:in `call'
        from Block.java:89:in `call'
        from RubyProc.java:274:in `call'
        from RubyProc.java:262:in `call19'
        from RubyProc$i$0$0$call19.gen:65535:in `call'
        from DynamicMethod.java:219:in `call'
        from DynamicMethod.java:215:in `call'
        from CachingCallSite.java:201:in `call'
        from CallTwoArgNode.java:59:in `interpret'
        from IfNode.java:117:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:190:in `call'
        from DefaultMethod.java:179:in `call'
        from CachingCallSite.java:312:in `cacheAndCall'
        from CachingCallSite.java:169:in `call'
        from CallOneArgNode.java:57:in `interpret'
        from NewlineNode.java:104:in `interpret'
        from BlockNode.java:71:in `interpret'
        from ASTInterpreter.java:75:in `INTERPRET_METHOD'
        from InterpretedMethod.java:212:in `call'
        from DefaultMethod.java:187:in `call'
        from RubyClass.java:563:in `finvoke'
        from RubyBasicObject.java:1691:in `send19'
        from RubyKernel.java:2117:in `send19'
        from RubyKernel$s$send19.gen:65535:in `call'
        from JavaMethod.java:283:in `call'

It goes on for longer than that but its just a bunch of dynamic method calls.

The error also presents different errors on puts "#{message}" and puts "#{message.strip}"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似狗非友 2024-12-14 20:17:59

该消息可能是 ruby​​ IO 类系列 http 中授予的另一种 ruby​​ 对象://www.ruby-doc.org/core/IO.html 不是一个字符串,而是来自 ssh 会话的某种缓冲区。尝试Marshal.dump(message.to_s),或者放入message.class来验证它到底是什么。

It might be that the message is another kind of ruby object conferring in the ruby IO family of classes http://www.ruby-doc.org/core/IO.html and not a String but some kind of buffer that comes from the ssh session. Try Marshal.dump(message.to_s), or puts message.class to verify what it actually is.

我爱人 2024-12-14 20:17:59

这是 JRuby 1.6.4 中的一个错误。它已在 1_6 分支中修复,应该在 1.6.5 版本中修复。

您可以在这里阅读更多相关信息:

https://jira.codehaus.org/browse/JRUBY-6116

长话短说:如果您想保留 1.6.4,请使用 str = Marshal.load(Marshal.dump(str))

编辑:1.6.5 已发布并且包含此修复程序。

This is a bug in JRuby 1.6.4. It has been fixed in the 1_6 branch and should be fixed in the 1.6.5 release.

You can read more about it here:

https://jira.codehaus.org/browse/JRUBY-6116

Long story short: use str = Marshal.load(Marshal.dump(str)) if you want to stay on 1.6.4

edit: 1.6.5 has been released and contains this fix.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文