Load Errors: Open-uri.rb:37 in 'open'

I have developed a plugin, but in some environments, it popups the following error.

image

The .rb file loads well on some computers, and also we all use the SketchUp version 2020 on Windows 10.

Could anyone help to solve this problem? Thanks in advance.

Post the message including the first few lines.
They’ll contain more useful info…

I see ā€˜SystemStack Error’ - …too deep…
What are you trying to pass ?

A ā€œstack level too deepā€ error suggests that you have an infinite recursion loop in your code. Based on the chain of error messages I would guess you are retrying an open uri call that fails.

1 Like
require 'open-uri'    
stringsfile = "C:/Users/Administrator/Desktop/test.txt"

open(stringsfile) {|f|
     string = f.read # This returns a string even if the file is empty.
}

If the input parameter is a local file path, then the SketchUp will popup the error.

And I try to use weblink such as ā€œhttp://www.google.com/ā€, it will work well and return the right result.

Yes, I try to use open() function in open-uri to open and read a local file.

And I have tested the above simple code segment with the ruby console in SketchUp, it also popups the same error.

The weird thing is that the open() function could open a weblink but not a local file.

There are many alternative ways to read local files that sidestep the limitations of open-uri - e.g. File.read_all(stringsfile) or perhaps the IO methods…

1 Like

I don’t know why the stack overflow is happening, but I notice that your ā€œstringsfileā€ variable is not a valid URI for a local file. It ought to start with file:// not just with the C: drive. Possibly there is a bug in open-uri in this situation?

I agree with TIG, use File.open or File.each or IO.readlines.

There is no real good reason do deal with open-uri quirks for local files.

1 Like

Appreciate for all the professional suggestion, and I have used File.open as an alternate.

And it works well in any Windows environment.

2 Likes

FYI - I have experienced this issue but in a Mac environment.

With open creating a stack-overflowing recursion?

correct

Did you find an alternative to open in your case? Or did you have to use open?

We switched to using File.open. I don’t recall why we were using open-uri open prior.

2 Likes